2012-03-02 119 views
1

我想在输入我的画布应用程序后删除待处理的应用程序请求。我按照https://developers.facebook.com/docs/requests/#deleting的指示向本文档中提到的URI发出了HTTP DELETE请求,使用请求ID来处理来自我的应用(可从Graph API访问)的请求以及用户访问令牌。我只会收到一条错误消息,说:“您请求的某些别名不存在。”我怀疑我的格式化这个URI的方式存在问题。下面是我做什么,使用Ruby on Rails和HTTParty:如何删除Facebook应用程序请求?

HTTParty.delete("https://graph.facebook.com/#{outstanding_app_request_ids}?access_token=[#{session[:access_token]}]") 

有没有人有一个URI,它成功地删除这些请求的例子吗?

回答

2

我已经找到了更好的解决方案,它使用考拉的宝石,并删除一举以批量要求的优秀应用程序的请求。以下是获取请求的代码,以及一次删除所有请求的代码。

@graph = Koala::Facebook::API.new(ACCESS_TOKEN) 
raw_requests = @graph.get_connections("me", "apprequests") 
app_request_ids = [] 
raw_requests.each do |request| 
    app_request_ids << request["id"] 
end 
if app_request_ids.size > 0 
    @graph.batch do |batch_api| 
    app_request_ids.each do |app_request_id| 
     batch_api.delete_object(app_request_id) 
    end 
    end 
end 
+0

蒂姆怀特的解决方案更好 – Calin 2012-05-14 14:09:44

+0

@卡琳,你为什么认为它更好? – ragingsquirrel3 2012-05-14 15:25:55

+3

也许人们认为这也是连续的?考拉批量api采取requests.each,然后在'结束'批处理。参考。 https://github.com/arsduo/koala/wiki/Batch-requests – PrasannaK 2012-07-02 10:37:00

1

打开这个网址:

https://graph.facebook.com/{outstandingapprequestids}_{userid}?access_token=ACCESS_TOKEN&method=DELETE 
+0

我仍然得到同样的错误。这对你有用吗? – ragingsquirrel3 2012-03-05 16:39:58

+0

sry这是错的,我的帖子更新 – 2012-03-05 17:09:46

+0

因此,我似乎无法得到'{'和'}'格式正确。它们不允许为原始码,并且使用百分比编码代码包含不需要的'/'。我尝试用'['按照Facebook的文档替换它们,并且仍然得到了803,别名不存在的错误。 – ragingsquirrel3 2012-03-05 18:39:20

3

使用考拉是最容易在Ruby中在我看来:

@graph = Koala::Facebook.API.new(ACCESS_TOKEN) #Get access to graph 
app_requests = @graph.get_connections(UID, 'apprequests') #Get app_requests 

app_requests.collect {|request| request['id']}.each do |id| 
    @graph.delete_object(id) # Delete app_request 
end 
+0

这里唯一的问题是请求被逐个删除。使用批量请求一次全部删除它们会更好。请参阅此问题的选定答案。 – ragingsquirrel3 2012-03-27 17:44:58

+0

delete_object(request.id)应该是delete_object(id) – chiurox 2012-05-19 00:33:17

相关问题