Facebook API返回对象ID的列表

时间:2019-09-29 22:55:44

标签: python facebook social-networking

我正在尝试从我的个人资料上的最新帖子中获取ID列表,以便我可以在其他位置分别对每个帖子执行操作,但是在将ID与其他帖子数据隔离时遇到了问题。它说posts对象是一个字典,但是当我尝试使用posts ['id']遍历它时,我只会获取myID,而当我在post posts [p]中用于p时,则会获取所有内容。我是python的新手,遇到了一些主要问题,如何获得仅id的列表?

import facebook
import json

token = {'****'}
graph = facebook.GraphAPI(token)
page_ids = []
myID = graph.request('/me?fields=id')
print(myID['id'])
posts = graph.get_object(id=myID['id'],fields='posts.fields(object_id)')
print(posts)



{'object_id': '503243983830603', 'id': '2894021623958853_2890876384273377'}, {'object_id': '402662493728056', 'id': '2894021623958853_2890866360941046'}, {'id': '2894021623958853_2890842810943401'}], 'paging': {'previous': 'https://graph.facebook.com/v4.0/2894021623958853/posts?fields=object_id&since=1569687697&access_token=EAAKsaVifZCCYBAE7ofO8qRSheQsBhi2mYrZB39wzfhCZAJ2ejGoyZAi8hdKZAoEjIWUEk7Y1Y8nCb9yrU17JEXf2jGMF7E4SVpneE3EYbCV2zDRb1K8ZCkcY5tQP00DALPWYXNLimGxyGsugwK5GPOZC19suEItAszJM4RHFaTUMMZBXiyiHH0mnzpdUP0vl2MklfCct4mk6EwZDZD&limit=25&__paging_token=enc_AdCi4Pnb01TJi24NGPgqiXLRi3AuoPtBkgJfx43aXRQwPPzkfcJ0BHQuqNXebzs5Vm01uEHcSrvAtTiYcTKvJu5raYCKn4pftMqeyD60hDz0PgZDZD&__previous=1', 'next': 'https://graph.facebook.com/v4.0/2894021623958853/posts?fields=object_id&access_token=EAAKsaVifZCCYBAE7ofO8qRSheQsBhi2mYrZB39wzfhCZAJ2ejGoyZAi8hdKZAoEjIWUEk7Y1Y8nCb9yrU17JEXf2jGMF7E4SVpneE3EYbCV2zDRb1K8ZCkcY5tQP00DALPWYXNLimGxyGsugwK5GPOZC19suEItAszJM4RHFaTUMMZBXiyiHH0mnzpdUP0vl2MklfCct4mk6EwZDZD&limit=25&until=1569590626&__paging_token=enc_AdDfKEIsYp9uDTOhVdXvJ2KKarEfKqyiV3stKSk3ZBPh5rNWDDihjnBZC29jw2xQF1fmjViUe18SIlW8CW4CVV5sFsEtxdSFOnQZA63RNgWrk4ZAqQZDZD'}}, 'id': '2894021623958853'}

0 个答案:

没有答案