简体   繁体   中英

Facebook canvas url with params?

I have a website in which i use the Facebook API to let users 'invite' their friends to my site. These friends will get an App invite on their Facebook and once they click and accept it, it opens a page of my site in side an iFrame (within Facebook).

That's all fine, but i would like to add a refer id to the URL. So i can tell from who they got the invitation.

Is it possible to add (dynamic) parameters to the canvas URL??

I haven't been able to find out how to do this.

(I'm using the JS library).

I am able to pass multiple params to my canvas page. Not quite sure why this is not working for you or for @JonCanning. I am able to successfully redirect to https://apps.facebook.com/MY-APP?param1=x&param2=y&param3=z and retrieve them within the code loaded in the iframe.

You cannot manipulate request urls if you use apprequests for invites though, so not sure how you plan to manipulate the request url. Is this a wall post mechanism?

But, if you are using apprequests for invites - you can pass an optional "data" param. This can be arbitrary JSON or a simple string. When a recipient clicks thru the invite, you will be provided a "request_id" param in the request redirector from Facebook. eg http:YOUR-INVITE-REDIRECT-URL?request_ids=REQUEST_ID. If multiple invites from the same app were sent to the user, you will get the request_ids as a comma separated list. You can make a call back to the facebook graph api endpoint for requests and get back all the info for the requests - including the "data" param you passed. This might work better for you since you have embedded all data in the request itself.

More info on dialogs here : https://developers.facebook.com/docs/reference/dialogs/requests/

A single parameter passed into your apps url is passed onto the iframe

http://apps.facebook.com/app_name/?param=hello

To add to @iyerrag's answer, to grab the data param from within your canvas handler, you have to call back into the facebook graph API. The call takes one of the request_ids passed in the http query and also an access token. I was able to use our app's access token (generated something like this Creating App Token ).

The returned JSON document contains the value you passed in the data param in key 'data'.

Here's the gist, in Python:

requestIDStr = self.request.get('request_ids','')
requestIDs = requestIDStr.split(',')
requestID = requestIDs[0]

if requestID:
   url = """https://graph.facebook.com/{}?access_token={}""".format(requestID, fbAccessToken)
   try:
      response = urllib2.urlopen(url)
      responseDoc = response.read()
      jsonResponse = json.loads(responseDoc)
      dataParam = jsonResponse['data']
   except Exception as e: logging.warning('unable to retrieve data param: {}'.format(e) )

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