2015年6月12日金曜日

Python, Facebookページに投稿する

このチュートリアルがシンプルでわかりやすい
http://nodotcom.org/python-facebook-tutorial.html
よくあるエラーの一例
http://stackoverflow.com/questions/8823049/facebook-graph-api-error
'publish_stream'とここでは書いてあるが'publish_pages'のことだと思われ(バージョンの問題かな)

このexampleに従うと「自分のアカウント」で投稿する
http://stackoverflow.com/questions/24052651/python-facebook-sdk-post-to-page
そのときのエラーの一例
http://stackoverflow.com/questions/19535885/oauth-exception-200-while-trying-to-post-to-groups-after-recent-facebook-mainte
「アプリの設定」でアプリ自体のpublicへの投稿を許可しておく必要がある(only meではダメ)

Facebookページへの写真投稿についてはハマった
HTTPのリクエストを自力で作るやつが結果的には容易だった
http://stackoverflow.com/questions/17691636/uploading-photos-or-videos-to-facebook-using-python
ここにあるのはvideosの例だけどphotosに書き換えればよい
あとは前述のこれ、
http://nodotcom.org/python-facebook-tutorial.html
のサンプルへの注記にあるようにappへのaccess tokenではなく、Facebookページに対するaccess tokenをゲットすればページ管理人として投稿できる

参考Graph APIのphoto部分のリファレンス
https://developers.facebook.com/docs/graph-api/reference/page/photos/ 

Facebook-SDKのリファレンス(post_wallはいいんだけどput_photoは使えなかった)
http://facebook-sdk.readthedocs.org/en/latest/api.html#put-photo
リファレンス全体(root node)
https://developers.facebook.com/docs/graph-api/reference/

http://facebook-sdk.readthedocs.org/en/latest/api.html#class-facebook-graphapi