我已经在Stackoverflow上广泛搜索了答案,但找不到它。我正在使用以下代码将照片上传到Facebook的粉丝页面中。有用。
但是,如您所见,attach dict中的picture变量引用了一个URL。我希望能够上载本地文件(例如,“ / foo / bar / hello.png”)。当我尝试使用本地路径而不是URL时,它在执行.put_wall_post()时停止,而没有打印错误,它只是停止,并且响应没有设置为任何值。
非常感谢您的投入。
import facebook
import urllib
import urlparse
access_token_page='XXX'
FACEBOOK_APP_SECRET = 'XXX'
FACEBOOK_PROFILE_ID = 'XXX'
oauth_args = dict(client_id = FACEBOOK_APP_ID,
client_secret = FACEBOOK_APP_SECRET,
grant_type = 'client_credentials')
oauth_response = urllib.urlopen('https://graph.facebook.com/oauth/access_token?' + urllib.urlencode(oauth_args)).read()
attach = {
"name": 'Hello world',
"link": 'http://www.example.com',
"caption": 'test post',
"description": 'some test',
"picture": 'http://somelocation.com/somepicture.png',
}
facebook_graph = facebook.GraphAPI(access_token_page)
try:
response = facebook_graph.put_wall_post('', attachment=attach)
except facebook.GraphAPIError as e:
print e
您需要使用该put_photo
方法上传本地数据。要将其发布到页面,请指定<page id>/photos
为album_id
:
f.put_photo(open('picture.jpg'), message='Test photo upload', album_id='140231988803001/photos')
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句