开发者

Facebook Invite User, retrieving the data field

Hi when my application lets a user invite their friends, I would like to append a tracking tag in the data field so that when someone receives that invite, I will be able to retrieve that tracking tag.

My problem is that once I pass the tracking tag, I don't know how to retrieve it when a user clicks on an application request.

My code for the invitation is

FB.u开发者_运维知识库i(                  
    {
    method: 'apprequests', 
    message: 'You should learn more about this awesome game.',
    data: UniqTrackIDInvite  //a randomly generated number
    }, 

and on my landing page, where a new user decides to accept my app or not after clicking on the, I would like to have a way to retrieve this


getting the request ids:

if(isset($_REQUEST['request_ids']))
    $reqIds = explode(',', $_REQUEST['request_ids']);

you may store them in the session to use them later

this is the api call:

public function getInvitationData($reqId){
    return $facebook->api('/'.$reqId, 'GET', array('access_token'=>$accessToken));
}

as the user may be invited by more than one user, he can hav several invites, so make a loop. also use a try/catch block, as a request id, which is already deleted, will throw an exception

foreach($reqIds as $reqId) {

    try{
        $invite = $application->facebook->getInvitationData($reqId);
        $data = explode('.', $invite['data']);

        if(sizeof($data) >= 3) list($in, $from, $code)=$data;

        // tadaaa
        echo $code;

    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜