对于具有所有权限的应用程序,无法获取Facebook页面的访问令牌 [英] Can't get access token for a facebook page for an application that has all the right permissions

查看:149
本文介绍了对于具有所有权限的应用程序,无法获取Facebook页面的访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SO社区



我试图将一个应用程序自动发送到我的Facebook页面。



这些是我采取的步骤:



A)我授权我的所有Facebook页面的应用程序,并授予offline_access权限,publish_stream和manage_pages使用

$ a
$ b $ = read_stream,publish_stream,manage_pages,offline_access,publish_actions

B)我请求了应用程序的访问令牌,那些权限

  https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=<app_id> & client_secret =< app_secure_key>& scope = manage_pages,offline_access,publish_stream 

C)想要获取页面的访问令牌,以便能够使用

 $ code > 

但是获取page_access_token是我失败的地方



这是我正在尝试的电话

  https://graph.facebook.com/<page_id>?fields=access_token&access_token=<app_access_token> 

而不是页面的访问令牌,我只是得到这个:

  {
id:< page_id>
}

任何人都有任何见识,我缺少得到。



/ Thomas

解决方案

我们刚刚设法在过去的几个天。这是一个总结。如果我详细说明了这一点,我很抱歉,但是你所做的几件事似乎有点错误。总结您的步骤:



如果您正在执行 step_A 正确,网址的外观似乎是正确的,那么最后你会收到一个CODE(而不是最后的访问令牌)。这将是使用您在步骤A中发送的重定向网址的重定向,因此请确保您的服务器正在接受在此指定的 redirectURL 的请求。它将以 http:// redirectURL?code = A_CODE_GENERATED_BY_SERVER 的形式,所以做params [code]应该得到你的代码。



Step_B可能是您稍微关闭的地方。您已将 CODE 从step_A发送回服务器。我看到您已经再次设置了一个范围参数,现在不需要(在 step_A 中完成)。 Step_B ,您的请求网址应如下所示:

  https://graph.facebook.com/oauth/ access_token?client_id = YOUR_APP_ID& redirect_uri = YOUR_URL& client_secret = YOUR_APP_SECRET& code = THE_CODE_FROM_ABOVE 

使用redirectURL,然后返回响应 。如果您具有正确的 Step_B 请求URI,您可以将其粘贴到浏览器位置栏中,并且响应将在浏览器本身中呈现。您可以使用 HTTPBuilder (这是我正在使用的)并捕获此响应体。它的形式是 access_token =< really_big_string>& expires =< time_to_live> 。解析这个回应,无论你喜欢哪种方式。



这也是一个access_token(让我们称之为 access_token_uno ),我想有一些事情你可以使用这个。我还没有尝试过,所以我们继续执行 Step_C 。我想你已经知道你的 PageID 。您必须以

  https://graph.facebook.com/<格式的URL发送access_token_uno到Facebook PAGEID>字段=&的access_token放大器; =的access_token< access_token_uno> 

响应将是一个JSON块的形式:

  {
access_token:< required_pa​​ge_access_token>
id:< PageID>
}

解析JSON块,你完成了。



要记住的一个小细节:redirectURL必须在 Step_A Step_B 中保持不变,否则事情就会失败。此外,我还没有尝试使用 offline_access 权限,但我不认为上述步骤会改变,即使是这样。


SO community,

I am stuck in my attempt to have an application post automatically to my Facebook page.

These are the steps I took:

A) I authorized my application for all my facebook pages and granted permissions offline_access, publish_stream and manage_pages using

https://www.facebook.com/dialog/oauth?client_id=<app_id>&redirect_uri=<url>&scope=read_stream,publish_stream,manage_pages,offline_access,publish_actions

B) I requested the access token for the application with those permissions

https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=<app_id>&client_secret=<app_secure_key>&scope=manage_pages,offline_access,publish_stream

C) I now want to get the access token for the page to be able to do the final post using

https://graph.facebook.com/feed?<page_access_token>&message=test&id=<page_id>&method=post

however getting the page_access_token is where I am failing

This is the call I am trying

https://graph.facebook.com/<page_id>?fields=access_token&access_token=<app_access_token>

but instead of the page's access token I just get this back:

{
   "id": "<page_id>"
}

Anyone has any insight what I am missing to get the .

/Thomas

解决方案

We just managed to get this working in this past couple of days. Here's a summary. I apologize if I am detailing it beyond necessary but a couple of things you have done seem a bit wrong. To sum up your steps:

If you are doing step_A correct, which by the looks of the URL seems all right, then at the end of it you will receive a CODE (not the final access token). This will be a redirection using the redirect URL you sent in step A, so make sure your server is accepting a request for that redirectURL specified there. It will be in the form http://redirectURL?code=A_CODE_GENERATED_BY_SERVER so doing params[code] should get you the CODE.

Step_B might be where you are slightly off. You have send the CODE from step_A back to the server. I see that you have set a scope parameter again which is now not necessary (it was done in step_A). Step_B your request URL should look like

https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&client_secret=YOUR_APP_SECRET&code=THE_CODE_FROM_ABOVE

This time Facebook sends back a Response not using the redirectURL though. If you have the correct Step_B request URI you can paste it in your browser location bar and the response will render in your browser itself. You can use an HTTPBuilder (that's what I am using) and capture this Response body. It is of the form access_token=<really_big_string>&expires=<time_to_live>. Parse this response whichever way you prefer.

This is also an access_token (let's call it access_token_uno) and I suppose there is some amount of things you can do using this. I haven't tried it myself though and so we proceed to Step_C. I suppose you already know your PageID. You have to send back access_token_uno to Facebook in a URL of the form

https://graph.facebook.com/<PageID>?fields=access_token&access_token=<access_token_uno>

The response will be a JSON block of the form:

{
   "access_token": <required_page_access_token>,
   "id": <PageID>
}

Parse the JSON block and you are done.

The one minor detail to remember: The redirectURL has to remain the same in Step_A and Step_B else the thing fails. Also, I haven't yet tried with the offline_access permission but I don't think the steps above will change even if that is the case.

这篇关于对于具有所有权限的应用程序,无法获取Facebook页面的访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆