英文:
how to get page id facebook pages using token pages
问题
当我执行这个函数时
def cari_id(access_token):
url = f"https://graph.facebook.com/v17.0/me/accounts?fields=id&access_token={access_token}"
response = requests.get(url)
data = response.json()
page_id = data["data"][0]["id"]
return page_id
使用 fastapi 帮助我上传动态时,出现如下错误
page_id = data["data"][0]["id"]
KeyError: 'data'
我根据这里的文档创建了这个程序
https://developers.facebook.com/docs/pages/getting-started/
这是 fastapi 的端点
@app.post("/post-to-feed")
async def post_feed(pesan: str, access_token: str= Header(..., description="meta token")):
page_id = cari_id(access_token)
response = create_feed(page_id, access_token, pesan)
return JSONResponse (response)
使用页面令牌获取页面 ID 以上传到 Facebook 页面的动态。
英文:
when I execute this function
def cari_id(access_token):
url = f"https://graph.facebook.com/v17.0/me/accounts?fields=id&access_token={access_token}"
response = requests.get(url)
data = response.json()
page_id = data["data"][0]["id"]
return page_id
using fastapi to help me upload feeds for some reason it always outputs an error like this
page_id = data["data"][0]["id"]
KeyError: 'data'
I created this program based on the documentation here
https://developers.facebook.com/docs/pages/getting-started/
here fastapi endpoint
@app.post("/post-to-feed")
async def post_feed(pesan: str, access_token: str= Header(..., description="meta token")):
page_id = cari_id(access_token)
response = create_feed(page_id, access_token, pesan)
return JSONResponse (response)
get page id using page token to upload to feed facebook pages
答案1
得分: 0
不要使用此网址,如果您使用页面令牌:https://graph.facebook.com/v17.0/me/accounts?fields=id&access_token=
请使用此网址:
https://graph.facebook.com/me?access_token=
完整的代码如下:
def cari_id(access_token):
token_pages_url = f'https://graph.facebook.com/me?access_token={access_token}'
token_pages = requests.get(token_pages_url)
data = token_pages.json()
page_id = data["id"]
return page_id
英文:
dont use this url if you use page token: https://graph.facebook.com/v17.0/me/accounts?fields=id&access_token=
use this url:
https://graph.facebook.com/me?access_token=
this full code:
def cari_id(access_token):
token_pages_url = f'https://graph.facebook.com/me?access_token={access_token}'
token_pages = requests.get(token_pages_url)
data = token_pages.json()
page_id = data["id"]
return page_id
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论