简体   繁体   English

使用Facebook Graph API发布评论时出错

[英]Error posting comments using Facebook Graph API

My aim is to post a comment to a particular post id using Facebook graph API. 我的目的是使用Facebook graph API向特定的帖子ID发表评论。

This is the code snippet for the same: 这是相同的代码段:

url = 'https://graph.facebook.com/v2.11/<post_id>/comments'
parameters = {'access_token': <FACEBOOK_ACCESS_TOKEN>, 'message': 'test comment'}
headers = {"content-type": "application/json"}
parameters = json.dumps(parameters)

response = requests.post(url, data=parameters, headers=headers, timeout=10)

I am calling this API inside my DJANGO POST API. 我正在DJANGO POST API中调用此API。

For Some Reason, Calling the Facebook API through this code doesnt work. 由于某些原因,通过此代码调用Facebook API无效。 The API call gets timeout after 10 seconds. API调用在10秒后超时。

If I call the Facebook API through Postman / YARC , the comment gets posted successfully. 如果我通过Postman / YARC调用Facebook API,则评论将成功发布。

Can any one tell me where I am going wrong? 谁能告诉我我要去哪里错了?

Python Requests example: Python请求示例:

import requests 汇入要求

url = " https://graph.facebook.com/v2.11/yourPostId/comments " url =“ https://graph.facebook.com/v2.11/yourPostId/comments

querystring = {"access_token":"yourtoken"} querystring = {“ access_token”:“您的令牌”}

payload = "message=test%20comment" headers = { 'content-type': "application/x-www-form-urlencoded", 'cache-control': "no-cache" } 有效负载=“ message = test%20comment”标头= {'content-type':“ application / x-www-form-urlencoded”,'cache-control':“ no-cache”}

response = requests.request("POST", url, data=payload, headers=headers, params=querystring) 响应= request.request(“ POST”,url,数据=有效载荷,标头=标头,参数=查询字符串)

print(response.text) 打印(response.text)


Python http.client example: Python http.client示例:

import http.client 导入http.client

conn = http.client.HTTPSConnection("graph.facebook.com") conn = http.client.HTTPSConnection(“ graph.facebook.com”)

payload = "message=test%20comment" 有效负载=“ message = test%20comment”

headers = { 'content-type': "application/x-www-form-urlencoded", 'cache-control': "no-cache" } 标头= {'content-type':“ application / x-www-form-urlencoded”,'cache-control':“ no-cache”}

conn.request("POST", "/v2.11/yourPostId/comments?access_token=yourtoken", payload, headers) conn.request(“ POST”,“ /v2.11/yourPostId/comments?access_token=yourtoken”,有效载荷,标头)

res = conn.getresponse() data = res.read() res = conn.getresponse()数据= res.read()

print(data.decode("utf-8")) 打印(data.decode(“ utf-8”))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM