如何在django中正确地对FacebookGraphAPI进行POST调用
我正在尝试从我的本地应用程序创建一个Facebook事件,我有一个表单,用户可以在其中输入事件信息。根据,我必须给如何在django中正确地对FacebookGraphAPI进行POST调用,django,facebook-graph-api,django-forms,Django,Facebook Graph Api,Django Forms,我正在尝试从我的本地应用程序创建一个Facebook事件,我有一个表单,用户可以在其中输入事件信息。根据,我必须给https://graph.facebook.com/USERID/events 为此,我使用了urlopen form_fields = { "access_token": request.user.get_profile().access_token, "name" : "name", "start_time" :
https://graph.facebook.com/USERID/events
为此,我使用了urlopen
form_fields = {
"access_token": request.user.get_profile().access_token,
"name" : "name",
"start_time" : "01/01/2012"
}
urllib2.urlopen(update_url,urllib.urlencode(form_fields))
运行我得到的代码
HTTP Error 400: Bad Request
调试程序后,变量值为
update_url = str: https://graph.facebook.com/XXXXXXXX/events
form_fields = dict: {'access_token': u'XXXXXX', 'start_time': datetime.datetime(2012, 1, 6, 0, 0), 'location': 'someplace', 'name': u'ab'}
更新url似乎是正确的,我猜问题在于表单字段。那么,我应该如何将这些字段提供给Facebook Graph API呢
Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Akshay\workspace\example\example\planpouchproto\views.py" in createPouch
20. graph.post('%s/events' %request.user.get_profile().facebook_id, **{"access_token": request.user.get_profile().access_token,"name" : cd['event_name'],"start_time" : "01/01/2012"})
File "C:\Users\Akshay\workspace\example\example\facepy\graph_api.py" in post
65. retry = retry
File "C:\Users\Akshay\workspace\example\example\facepy\graph_api.py" in _query
240. return load(method, url, data)[0]
File "C:\Users\Akshay\workspace\example\example\facepy\graph_api.py" in load
196. result = self._parse(response.content)
File "C:\Users\Akshay\workspace\example\example\facepy\graph_api.py" in _parse
282. error.get('code', None)
Exception Type: OAuthError at /pouch/
Exception Value:
让与Facebook的互动更简单,试试看
将事件发布到图表中类似于
graph.post('USERID/events', form_fields)
要调试,您可以通过发布注释来测试身份验证是否有效:
graph = GraphAPI(request.user.get_profile().access_token)
graph.post(path="me/feed", message="hello FB", caption="hello FB", description="hello FB")
然后你可以缩小你的问题范围。让与Facebook的互动更简单,试试看
将事件发布到图表中类似于
graph.post('USERID/events', form_fields)
要调试,您可以通过发布注释来测试身份验证是否有效:
graph = GraphAPI(request.user.get_profile().access_token)
graph.post(path="me/feed", message="hello FB", caption="hello FB", description="hello FB")
然后可以缩小问题的范围。出现此错误-不支持的操作数类型为-:“dict”和“int”。这就是我试过的。graph.post(“%s/events”%request.user.get_profile().facebook_id,{“access_token”:request.user.get_profile().access_token,“name”:cd['event_name'],“start_time”:“01/01/2012”})Try:graph.post(“%s/events”%request.user.get_profile().facebook_id,**{“access_token”:request.user.get_profile().access_token:“access”;“name”:cd['event_name',“start_time”:“01/01/2012”})出现了一个非常奇怪的错误,“OAuthError at/pocket/,未提供任何异常“奇怪的错误。你确定其他的GraphAPI电话有效吗?尝试阅读一些信息,发表评论等。有一个更详细的回溯也很好。下一个调试步骤:重要的是要知道是否不仅得到了工作,而且还有一些需要授权的调用,如提交评论。然后我们知道这是一个令牌和权限问题,还是只是这个特定的事件发布问题。我将用示例代码更新我的答案以测试POST。出现此错误-不支持的操作数类型-:“dict”和“int”。这就是我试过的。graph.post(“%s/events”%request.user.get_profile().facebook_id,{“access_token”:request.user.get_profile().access_token,“name”:cd['event_name'],“start_time”:“01/01/2012”})Try:graph.post(“%s/events”%request.user.get_profile().facebook_id,**{“access_token”:request.user.get_profile().access_token:“access”;“name”:cd['event_name',“start_time”:“01/01/2012”})出现了一个非常奇怪的错误,“OAuthError at/pocket/,未提供任何异常“奇怪的错误。你确定其他的GraphAPI电话有效吗?尝试阅读一些信息,发表评论等。有一个更详细的回溯也很好。下一个调试步骤:重要的是要知道是否不仅得到了工作,而且还有一些需要授权的调用,如提交评论。然后我们知道这是一个令牌和权限问题,还是只是这个特定的事件发布问题。我将用示例代码更新我的答案以测试帖子。