我如何获取Facebook访问令牌以使应用程序发布到公司墙上? [英] How do I obtain a Facebook access token for an app to post on a company wall?

查看:46
本文介绍了我如何获取Facebook访问令牌以使应用程序发布到公司墙上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我正在尝试做的.我已经创建了我的Facebook应用程序,并且能够使用Graph API资源管理器在右上角指定该应用程序.

So here is what I am trying to do. I have created my Facebook application and I have been able to use the Graph API explorer to specify the application in the top right.

一些更详细的信息,我正在使用C#在内部应用程序的功能中进行编码,以使其正常工作.

Some more detailed information, I am using C# to code in the functionality to our in-house app to get this to work.

之后,我进入url部分并输入以下地址.

After that I go to the url section and type in the following address.

https://graph.facebook.com/MyCompanyPage

然后点击提交".它将在资源管理器中导航并显示该页面的信息.好了,然后为我的应用获取我的access_token,然后点击获取访问令牌->指定我的扩展权限->然后再次点击获取访问令牌.一切都很好,我可以使用我们的Facebook应用程序成功发布到Facebook.

Then hit submit. It will navigate and display the information for that page below in the explorer. Well then to get my access_token for my app I go up and hit Get Access Token->Specify my Extended Permissions->Then hit Get Access Token again. All that is well and good and I can post to Facebook using our Facebook app successfully.

问题是access_token即将到期,我正在使用手动检索方法来获取访问令牌.

The problem is that the access_token is expiring and I am using a manual method of retrieval to get the access token.

这是我尝试使用GIT的示例之一进行的操作.

Here is what I have tried doing using one of the examples from GIT.

FacebookClient client = new FacebookClient();
dynamic parameters = new ExpandoObject();
parameters.client_id = "MYAPPID"; // Or does this need to be my CompanyPage ID??
parameters.redirect_uri = "https://www.facebook.com/connect/login_success.html";
// The requested response: an access token (token), an authorization code (code), or both (code token).
parameters.response_type = "token";
// list of additional display modes can be found at http://developers.facebook.com/docs/reference/dialogs/#display
parameters.display = "popup";
// add the 'scope' parameter only if we have extendedPermissions.
parameters.scope = "publish_stream,manage_pages,status_update";
// when the Form is loaded navigate to the login url.
Uri LoginURL = client.GetLoginUrl(parameters);

// whenever the browser navigates to a new url, try parsing the url.
// the url may be the result of OAuth 2.0 authentication.
FacebookOAuthResult oauthResult;
if (client.TryParseOAuthCallbackUrl(LoginURL, out oauthResult)) {
     // The url is the result of OAuth 2.0 authentication
} else {
     // The url is NOT the result of OAuth 2.0 authentication.
}

现在,当我尝试为自己获取应用程序的访问令牌时,此方法对我有用.但是,我需要该行为以与Graph API Explorer相同的方式进行操作.我需要它像资源管理器一样工作的原因是因为我想在实际公司页面下使用Facebook应用程序发布帖子,因此公司页面实际上是在发布Facebook帖子,而不是用户.就像我在上面说过的那样,我能够通过Graph API Explorer成功完成此操作,但是在C#中却没有成功完成此操作.

Now this works for me when I am trying to obtain an access token for the app for myself. However, I need the behavior to operate in the same way that it does for the Graph API Explorer. The reason I need it to work like the Explorer is because I wanted to make posts using the Facebook application under the actual Company Page, so it appears that the Company Page is actually making the Facebook post and not a user. Like I have said above I am able to successfully do this through the Graph API Explorer but haven't been successful doing this in C#.

推荐答案

为了代表Page使用Graph API,您需要获取Page访问令牌-有关更多详细信息,请参见此处:

in order to use Graph API on behalf of a Page, you need to get Page access token - see here for more details: https://developers.facebook.com/docs/authentication/pages/

  1. 验证用户身份并请求 manage_pages 权限
  2. 获取用户管理的页面列表
  3. 解析列表并获取令牌-并将其发布到供稿中.

这篇关于我如何获取Facebook访问令牌以使应用程序发布到公司墙上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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