Facebook API - 删除状态
在 PHP 中,我使用curl 将删除发送到 fb graph api - 但我收到以下错误;
{"error":{"type":"GraphMethodException","message":"Unsupported delete request."}}
我正在使用的代码是;
$ch = curl_init("https://graph.facebook.com/" . $status_id . "");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_CAINFO, NULL);
curl_setopt($ch, CURLOPT_CAPATH, NULL);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
$result = curl_exec($ch);
echo $result;
$query 包含访问令牌。
In PHP, I'm using curl to send a delete to the fb graph api - and yet I'm getting the following error;
{"error":{"type":"GraphMethodException","message":"Unsupported delete request."}}
The code I'm using is;
$ch = curl_init("https://graph.facebook.com/" . $status_id . "");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_CAINFO, NULL);
curl_setopt($ch, CURLOPT_CAPATH, NULL);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
$result = curl_exec($ch);
echo $result;
$query contains the access token.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
固定的!
删除时必须将 userid 添加到对象 ID 前面:
DELETE https://graph.facebook.com/ 673509687_104812882909249?access_token={access_token}
在哪里
673509687 是我的用户ID,104812882909249 是对象ID
Fixed!
You have to prepend the userid to the object ID when deleting:
DELETE https://graph.facebook.com/673509687_104812882909249?access_token={access_token}
where
673509687 is my userID and 104812882909249 is the objectID
对于仍在为此苦苦挣扎的人,我发现我的问题是尝试删除我之前使用 PHP SDK 创建的应用程序请求,这导致了此错误。
(#2) 无效参数:错误/警告消息正文。标题是:无效参数
问题本质上是使用哪个访问令牌;用户或应用程序。
我正在研究的具体场景是,我的应用程序中的用户邀请了 Facebook 好友(使用应用程序请求),但随后想要撤销该邀请。在本例中,我想删除之前在 Facebook 上创建的应用程序请求。但是,此时登录的用户不是应用程序请求的接收者,而是发送者。
查看 PHP SDK 代码,它会自动使用用户访问令牌(如果有)而不是应用程序访问令牌。事实上,似乎没有办法从 SDK 显式获取应用程序令牌。
当尝试使用以下命令删除应用程序请求时...
$facebook->api('/'.$fb_request_id, 'DELETE');
...并让 PHP SDK 选择用户令牌,我收到了 (#2) 无效参数错误消息。但是,如果我手动构建应用程序访问令牌(其中格式为“$app_id|$app_secret”并将其作为第三个参数中的数组键传递...
$facebook->api('/'.$fb_request_id, 'DELETE', array('access_token' => $app_access_token);
..然后调用成功。
因此,如果当前用户不是应用程序的接收者,则本质上您需要使用应用程序访问令牌来删除应用程序请求。 我希望
这可以帮助其他遇到同样问题的人。
For anyone still struggling with this, I found out what my issue was attempting to delete application requests that I had previously created using the PHP SDK, which was resulting in this error.
(#2) Invalid parameter: Body of an error/warning message. Title is: Invalid parameter
The problem was essentially with which access token was being used; user or application.
The specific scenario I was working on was where a user in my application has invited a friend Facebook (using an app request) but then wants to revoke that invite. In this case I want to delete the app request on Facebook that was previously created. However, at this point in time, the logged in user is not the recipient of the app request, but the sender.
Looking at the PHP SDK code, it automatically uses the user access token if it has one, over the application access token. In fact, there doesn't appear to be a way to explicitly get the application token from the SDK.
When attempting to delete the app request using the following...
$facebook->api('/'.$fb_request_id, 'DELETE');
...and letting the PHP SDK choose the user token, I received the (#2) Invalid parameter error message. However, if I manually construct the application access token (where the format is "$app_id|$app_secret" and pass it as an array key in a third parameter...
$facebook->api('/'.$fb_request_id, 'DELETE', array('access_token' => $app_access_token);
..then the call succeeds.
So, essentially you need to use the application access token to delete the app requests if the current user is not the recipient of the app request.
I hope this helps anyone else struggling with the same issue.
我稍微修改了你的代码。 (如果正确完成,应该回显“true”)这是目前对我有用的内容。
另请注意,这不会删除通过 Facebook 创建的事件。这就是您收到权限错误的原因。这只会删除通过您的应用程序创建的事件...(链接到 $app_id、$app_secret 的应用程序)
I modified your code slightly. (Should echo "true" if done correctly) Here's what is currently working for me.
Also note this does not erase events created via Facebook.That's why your receiving the permissions error. This only erases events created through your application... (application linked to $app_id, $app_secret)
我唯一能想到的尝试是
1) 使用“method=delete”执行 POST 请求,看看是否有效
2) 手动查看生成的 HTTP 请求,看看是否有问题 - 然后您可以隔离问题
The only thing I can think to try is to
1) do a POST request with "method=delete" to see if that works
2) manually look at the produced HTTP request to see if something looks wrong -- then you can isolate the problem
它只是意味着该特定对象不支持 HTTP 删除方法。
一种选择是使用 Http POST 并将 method=delete 添加到参数查询中。确保您的应用程序具有
publish_stream
权限,否则您将永远无法发布 Feed。权限由 Facebook 完成。
It simply means that the HTTP delete method isn't supported for that specific object.
One option is to use Http POST and add method=delete to the parameter query. Make sure that your application has a
publish_stream
permission else you can never publish a feed.Permissions are done by Facebook.
关于这个答案:
不幸的是,这只适用于用户访问令牌,而不是当您尝试使用 PHP 语言等在服务器上删除应用程序请求(使用应用程序访问令牌)时。
如果您有使用应用程序访问令牌删除应用程序请求的解决方案,请描述它。感谢您的帮助!
About this answer:
Unfortunately this will only work with a user-accesstoken and not when you try to delete an apprequest on the server (with the app-access-token) using for example the PHP language.
If you have a solution for deleting apprequests using the app-access-token then please describe it. Thanks for your help!