所以这就是我想要做的。我已经创建了我的 Facebook 应用程序,并且能够使用 Graph API 资源管理器在右上角指定应用程序。
一些更详细的信息,我正在使用 C# 对我们内部应用程序的功能进行编码,以使其正常工作。
之后,我转到 url 部分并输入以下地址。
https://graph.facebook.com/MyCompanyPage
然后点击提交。它将在资源管理器中导航并显示该页面下方的信息。那么为了获得我的应用程序的access_token,我上去点击获取访问令牌->指定我的扩展权限->然后再次点击获取访问令牌。一切都很好,我可以使用我们的 Facebook 应用程序成功发布到 Facebook。
问题是 access_token 即将过期,我正在使用手动检索方法来获取访问令牌。
这是我尝试使用 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 相同的方式运行。我需要它像 Explorer 一样工作的原因是因为我想在实际的公司页面下使用 Facebook 应用程序发布帖子,所以看起来公司页面实际上是在发布 Facebook 帖子而不是用户。就像我上面所说的,我可以通过 Graph API Explorer 成功地做到这一点,但在 C# 中没有成功做到这一点。