使用 FB graph api 和 appengine-python SDK 创建相册的代码是什么?
我在 PHP 中找到了以下代码..
python 中的等效代码是什么?
//At the time of writing it is necessary to enable upload support in the Facebook SDK, you do this with the line:
$facebook->setFileUploadSupport(true);
//Create an album
$album_details = array(
'message'=> 'Album desc',
'name'=> 'Album name'
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);
//Get album ID of the album you've just created
$album_uid = $create_album['id'];
//Upload a photo to album of ID...
$photo_details = array(
'message'=> 'Photo message'
);
$file='app.jpg'; //Example image file
$photo_details['image'] = '@' . realpath($file);
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
i found the follwing code in PHP ..
what is the equivalent code in python to do that ?
//At the time of writing it is necessary to enable upload support in the Facebook SDK, you do this with the line:
$facebook->setFileUploadSupport(true);
//Create an album
$album_details = array(
'message'=> 'Album desc',
'name'=> 'Album name'
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);
//Get album ID of the album you've just created
$album_uid = $create_album['id'];
//Upload a photo to album of ID...
$photo_details = array(
'message'=> 'Photo message'
);
$file='app.jpg'; //Example image file
$photo_details['image'] = '@' . realpath($file);
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 facebook 的人此处所写,他们将不再支持 python facebook sdk,因此最好制作通过本机 python 工具发出请求。
创建相册:
上传图像:
我没有找到使用 urllib2 发送多部分/表单数据的简短方法,因此我使用了此答案中的示例 https://stackoverflow.com/a/6843405/592737
但是如果你使用的是 facebook python-sdk 的某个分支(例如 https://github.com/pythonforfacebook/facebook-sdk)你可以用更短的方式做到这一点:
As facebook guys wrote here, they will no longer support python facebook sdk, so it better to make requests via native python tools.
Creating the album:
Uploading image:
I didn't find a short way to send multipart/form data using urllib2, so I used example from this answer https://stackoverflow.com/a/6843405/592737
But if you're using some fork of facebook python-sdk (like https://github.com/pythonforfacebook/facebook-sdk) you can do it shorter way:
Facebook 不支持,但您应该考虑 http://code.google.com/p/gae -simpleauth/ 用于 oauth 部分。
然后,正如其他答案所暗示的那样,使用像 urllib2 这样的 Python 库来进行图形调用(可能还有 simplejson 来解释响应)
Not supported by Facebook, but you should consider http://code.google.com/p/gae-simpleauth/ for the oauth piece.
Then, as other answers imply, use Python libs like urllib2 to make the graph calls (and possibly simplejson to interpret the responses)