facebook python-sdk post_to_wall附件 [英] facebook python-sdk post_to_wall attachment
问题描述
您好
我在谷歌appengine上使用python-sdk(http://github.com/facebook/python-sdk.git)。
我运行的是新闻源示例。
在facebook.py中,我必须导入urllib2
然后更改
file = urllib.urlopen(https://graph.facebook.com/+ path +?+
urllib.urlencode(args),post_data )
to
code> file = urllib2.urlopen(https://graph.facebook.com/+ path +?+
urllib.urlencode(args),post_data)
现在基本的应用程序正常工作。但是,如果我在 facebookclient.py
中更改了try:
/ pre>
self.graph.put_wall_post(message)
除了异常,e:
self.response.out.write(e)
return
到
try:
attachment = {}
message = message
caption ='test caption'
附件['caption'] = caption
附件['name'] ='test name'
附件['description'] ='test description'
self.graph.put_wall_post(message,attachment = attachment)
除了异常,e:
self.response.out.write(e)
return
我会收到错误(在 http:// localhost:8080 ):
HTTP错误400:错误请求
和appengine开发服务器抱怨:
INFO 2010-10-24 17:20:44,483 dev_appserver.py:3275]POST / post HTTP / 1.1302 -
警告2010-10-24 17: 20:44,570 urlfetch_stub.py:284]从URLFetch请求中删除禁止的标头:['主机']
INFO 2010-10-24 17:20:48,167 dev_appserver.py:3275]GET / HTTP / 1.1200 -
INFO 2010-10-24 17:20:48,292 dev_appserver.py:3275]GET /static/base.css HTTP / 1.1200 -
警告2010-10-24 17:21:19,343 urlfetch_stub.py:284]从URLFetch请求中剥离禁止标题:['Content-Length','Host']
INFO 2010-10-24 17:21 :20,634 dev_appserver.py:3275]POST / post HTTP / 1.1200 -解决方案通过使用put_object来解决问题的post_to_wall:
请参阅 http://developers.facebook.com/ docs / reference / api / post 为例,介绍如何发布卷曲self.graph.put_object(me,feed,message = message,
link = http://leona-nachhilfe.appspot.com,
picture =http://leona-nachhilfe.appspot.com/static/images/logo.png,
name =LeONa-测验,
description =Orges erreichte 45.Punkte,
actions = {'name':'Zu den Quiz-Aufgaben','link':'http://leona-nachhilfe.appspot .com'},
privacy = {'value':'ALL_FRIENDS'}
)
Hi I am using the python-sdk (http://github.com/facebook/python-sdk.git) on google appengine. I am runnig the "newsfeed" example.
In facebook.py i had to import urllib2
and then changefile = urllib.urlopen("https://graph.facebook.com/" + path + "?" + urllib.urlencode(args), post_data)
to
file = urllib2.urlopen("https://graph.facebook.com/" + path + "?" + urllib.urlencode(args), post_data)
Now the basic application works. However if I change
in facebookclient.pytry: self.graph.put_wall_post(message) except Exception, e: self.response.out.write(e) return
to
try: attachment = {} message = message caption = 'test caption' attachment['caption'] = caption attachment['name'] = 'test name' attachment['description'] = 'test description' self.graph.put_wall_post(message, attachment=attachment) except Exception, e: self.response.out.write(e) return
i will get the error (on http://localhost:8080) :
HTTP Error 400: Bad Request
and the appengine development server complains:
INFO 2010-10-24 17:20:44,483 dev_appserver.py:3275] "POST /post HTTP/1.1" 302 - WARNING 2010-10-24 17:20:44,570 urlfetch_stub.py:284] Stripped prohibited headers from URLFetch request: ['Host']
INFO 2010-10-24 17:20:48,167 dev_appserver.py:3275] "GET / HTTP/1.1" 200 -
INFO 2010-10-24 17:20:48,292 dev_appserver.py:3275] "GET /static/base.css HTTP/1.1" 200 -
WARNING 2010-10-24 17:21:19,343 urlfetch_stub.py:284] Stripped prohibited headers from URLFetch request: ['Content-Length', 'Host']
INFO 2010-10-24 17:21:20,634 dev_appserver.py:3275] "POST /post HTTP/1.1" 200 -解决方案Solved the problem by using put_object instead of post_to_wall:
see http://developers.facebook.com/docs/reference/api/post for an example on how to post with curlself.graph.put_object("me", "feed", message=message, link="http://leona-nachhilfe.appspot.com", picture="http://leona-nachhilfe.appspot.com/static/images/logo.png", name = "LeONa-Quiz", description = "Orges erreichte 45.Punkte", actions = {'name': 'Zu den Quiz-Aufgaben', 'link': 'http://leona-nachhilfe.appspot.com'}, privacy = {'value': 'ALL_FRIENDS'} )
这篇关于facebook python-sdk post_to_wall附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!