【发布时间】:2018-05-21 11:19:56
【问题描述】:
我正在尝试使用 'since' 和 'until' 从我管理的 Instagram 业务资料中检索上个月的媒体帖子,但它似乎无法正常工作,因为 API 返回的帖子超出了我选择的时间范围。
我正在使用以下字符串来调用 API:
business_profile_id/media?fields=timestamp&since=2018-04-01&until=2018-04-30
而 Python sn-p 是这样的(使用来自 facebook-python-sdk 的相同 init 脚本)
import facebook
graph = facebook.GraphAPI(access_token)
profile = graph.get_object(user)
posts = graph.get_connections(profile['id'], 'media?fields=caption,permalink,timestamp&since=2018-04-01&until=2018-04-30')
get.connections 在哪里
def get_connections(self, id, connection_name, **args):
"""Fetches the connections for given object."""
return self.request(
"{0}/{1}/{2}".format(self.version, id, connection_name), args)
请求是
def request(
self, path, args=None, post_args=None, files=None, method=None):
"""Fetches the given path in the Graph API.
We translate args to a valid query string. If post_args is
given, we send a POST request to the given path with the given
arguments.
"""
if args is None:
args = dict()
if post_args is not None:
method = "POST"
# Add `access_token` to post_args or args if it has not already been
# included.
if self.access_token:
# If post_args exists, we assume that args either does not exists
# or it does not need `access_token`.
if post_args and "access_token" not in post_args:
post_args["access_token"] = self.access_token
elif "access_token" not in args:
args["access_token"] = self.access_token
try:
response = self.session.request(
method or "GET",
FACEBOOK_GRAPH_URL + path,
timeout=self.timeout,
params=args,
data=post_args,
proxies=self.proxies,
files=files)
except requests.HTTPError as e:
response = json.loads(e.read())
raise GraphAPIError(response)
headers = response.headers
if 'json' in headers['content-type']:
result = response.json()
elif 'image/' in headers['content-type']:
mimetype = headers['content-type']
result = {"data": response.content,
"mime-type": mimetype,
"url": response.url}
elif "access_token" in parse_qs(response.text):
query_str = parse_qs(response.text)
if "access_token" in query_str:
result = {"access_token": query_str["access_token"][0]}
if "expires" in query_str:
result["expires"] = query_str["expires"][0]
else:
raise GraphAPIError(response.json())
else:
raise GraphAPIError('Maintype was not text, image, or querystring')
if result and isinstance(result, dict) and result.get("error"):
raise GraphAPIError(result)
return result
基本上我想获得一段时间的帖子,然后获得每个帖子的见解。
以前有人遇到过这个问题吗?
【问题讨论】:
-
我偶然发现了同样的问题。到目前为止,我已经尝试将 'since' 和 'until' 与 UNIX 时间戳一起使用,因为看起来他们正在使用该格式来过滤帐户级别的数据,但没有运气。发布此内容后,您找到解决方案了吗?
-
嗨弗拉维恩,我在下面发布了更新。
-
这篇文章已有 1 年历史。是否有任何已知的更新?
标签: python python-3.x facebook-graph-api instagram instagram-api