I'd like my Facebook canvas app to send an App Notification to a user's friend when they interact with the app. Here is my server-side code (using App Engine and urllib). conf.FACEBOOK_APP_ACCESS_TOKEN
is an App Access Token which I got by making a single call to the Graph API and then hardcoding the returned value, as explained in the link. The app access token looks something like:
426547656256546|4fhe34FJdeV3WvfF6SNfehs7GfW
This isn't my actual token: I've substituted numbers for other numbers, capital letters for other capital letters, etc, so you can see the format.
url = 'https://graph.facebook.com/'+friendID+'/notifications'
values = {'access_token' : conf.FACEBOOK_APP_ACCESS_TOKEN,
'href' : 'http://localhost:8080/',
'template' : '@['+userID+'] says hi.'}
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
urllib2.urlopen(req)
urlopen
gives the errors:
WARNING Stripped prohibited headers from URLFetch request: ['Content-Length', 'Host']
ERROR HTTP Error 403: Forbidden
What do I need to correct in this code to successfully send an app notification?
App notifications can only be send from Canvas apps. My app was set to Website with Facebook Login
in the Facebook settings, which doesn't allow notifications. To solve the problem, I just checked App on Facebook
in addition to Website with Facebook Login
(though I believe it works with only App on Facebook
as well) and specified a canvas URL.
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.