简体   繁体   中英

Facebook SDK - Handling application invites?

With the Facebook SDK it seems like they allow you to invite your friends to join the application through the AppRequest section of the SDK . However I don't see anywhere in the SDK where you can reward users for inviting friends. I know this is possible because it's been done so many times, so how it can be done?

For example, lets say:

1. User A invites User B to use the application.
2. User B downloads the application.
3. User A receives 100 coins for inviting User B.

I'm completely lost here, examples using any SDK, regardless of language, would be appreciated.

Since Facebook app invites are based on AppLinks , that is where you need to look for a solution. I will explain this by using an Android example scenario.

When constructing an app invite ( using the dialog ), you are specifying an AppLinks URL. This URL can be unique to each user that sends out invites, or even to each individual invite. Eg: https://www.example.com/invite_applink?invite_id=12345 . By creating one AppLink url for eg each user who invites others, you embed invite-sender attribution (which is what you are saying you want) into your AppLinks URL.

The way the Facebook app figures out how to open your app from the "app invites" section, is by following the AppLinks specification . This specification states that in the <head> section of the HTML document that lives at https://www.example.com/invite_applink , there has to be appropriate <meta> data that describes how your app can be opened/deep-linked into. One part of that is the al:android:url property, which could be used like this: <meta property="al:android:url" content="example://invite_from_fb?invite_id=12345" />

Observe how the url contains a parameter invite_id=12345 , where 12345 is the same value as the one used in the invite_id parameter of the AppLinks URL above. When the invited user now opens the app from the deep-linking URI example://invite_from_fb?invite_id=12345 , the app will be opened from an intent that contains this information.

When your app's Activity opens you can grab the Intent that opened the Activity , and get from it the Uri that was used to open the app: Intent.getData() . More on this on the Android docs on " Allowing other Apps to Start Your Activity "

At this point, the ID that attributes an app invite to a user has made from the sender into the running app of the recipient. Now the app on the recipient's device needs to call your server and let it know which invite_id was used to open it. To avoid that multiple such attributions originate from one user (who may have received invites from multiple people), you could hold off on sending this attribution data until the user has performed some sort of login (eg Facebook Login) and you are able to ignore eg all attributions after the first one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM