我創建了一個Facebook頁面,並且正在嘗試使用下面的代碼在頁面牆上發佈信息。它是用Python編寫的,並使用Facebook SDK。發佈到頁面的Python facebook SDK權限錯誤
def main():
cfg = {
"page_id" : "PAGE_ID", # Step 1
"access_token" : "USER_ACCESS_TOKEN" # Step 3
}
graph = facebook.GraphAPI(cfg['access_token'])
id = graph.get_object('me')['id']
print(graph.get_permissions(user_id=id))
resp = graph.get_object('me/accounts')
page_access_token = None
for page in resp['data']:
if page['id'] == cfg['page_id']:
page_access_token = page['access_token']
api = facebook.GraphAPI(page_access_token)
msg = "Hello, world!"
print(api.get_permissions(user_id=id))
print(api.put_wall_post(msg))
這是給下面的輸出錯誤:
{'user_posts', 'publish_actions', 'public_profile', 'pages_manage_cta', 'manage_pages'}
{'user_posts', 'publish_actions', 'public_profile', 'pages_manage_cta', 'manage_pages'}
print(api.put_wall_post(msg))
File "C:\Python34\lib\site-packages\facebook_sdk-3.0.0a0-py3.4.egg\facebook\__init__.py", line 188, in put_wall_post
File "C:\Python34\lib\site-packages\facebook_sdk-3.0.0a0-py3.4.egg\facebook\__init__.py", line 169, in put_object
File "C:\Python34\lib\site-packages\facebook_sdk-3.0.0a0-py3.4.egg\facebook\__init__.py", line 298, in request
facebook.GraphAPIError: (#200) The user hasn't authorized the application to perform this action
我不明白我做錯了什麼?我給了用戶正確的權限。我查了其他重複的問題,但他們的解決方案不適用於當前的FacebookSDK。有人可以幫幫我嗎?
用戶需要授予應用程序publish_pages才能在頁面上發佈 – WizKid
非常感謝您,我一直在努力工作6個小時來實現這一目標。 – pratibha
請將其發佈爲答案,以便我可以將其標記爲已接受。 – pratibha