首页 文章

如何设置Facebook应用程序设置

提问于
浏览
0

我为客户编写了一个ASP.NET页面,该页面使用C#Facebook API发布到Facebook .

//发布到Facebook .

//构建参数字典postArgs = new Dictionary(); postArgs [“message”] =“Hello World!”;

//发帖var response = api.Post(“/ me / feed”,postArgs);

//获取新帖子ID var id = response.Dictionary [“id”] . String;

我使用我个人的Facebook帐户注册了应用程序http://developers.facebook.com/setup/来测试集成 .

在“选择您的应用如何与Facebook集成”部分下,我选择了“网站”并输入了网站网址 .

当我在我的帐户设置下查看应用程序时,它具有以下“应用程序设置”:访问我的基本信息;访问我的profiel信息;以我的身份发布到Facebook;随时访问我的数据 .

一切都很好 .

我使用客户的Facebook帐户设置了相同的应用程序 . 我将客户端ID和客户端密钥更改为新的详细信息 .

它不再有效 .

当我在客户的帐户设置下查看应用程序时,它没有上面列出的任何“应用程序设置” .

与我的客户的“应用程序设置”相比,我的“应用程序设置”允许应用程序更好地访问我的Facebook帐户 - 我想这就是为什么它无法发布到我客户的Facebook帐户 .

不幸的是,我不记得在我的Facebook帐户上明确设置这些“应用程序设置” . 我似乎也无法在Facebook上的任何地方找到我可以在我的客户帐户上设置这些“应用程序设置”的地方 .

请有人请帮助/指导我 .

提前致谢 .

亲切的问候

沃尔特

更新:

这是我的代码:

首先我验证:

// Authenticate.
string clientId = "0123456789";
string redirectUrl = "http://www.abc.com/oauth/oauth-redirect.aspx";

Response.Redirect(string.Format("https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}", clientId, redirectUrl));

接下来执行oauth / oauth-redirect.aspx页面 .

这是oauth / oauth-redirect.aspx.cs的代码隐藏:

if (Request.Params["code"] != null)
{
    Facebook.FacebookAPI api = new Facebook.FacebookAPI(GetAccessToken());

    // Build the Arguments.
    Dictionary postArgs = new Dictionary();
    postArgs["message"] = "Hello World";
    postArgs["link"] = "http://www.abc.com";
    postArgs["name"] = "abc.com";
    postArgs["type"] = "link";
    postArgs["caption"] = "www.abc.com";

    // Post.
    var response = api.Post("/me/feed", postArgs);

    // Get New Post ID.
    var id = response.Dictionary["id"].String;
}

private string GetAccessToken()
{
    if (HttpRuntime.Cache["access_token"] == null)
        {
            Dictionary args = GetOauthTokens(Request.Params["code"]);

            HttpRuntime.Cache.Insert("access_token", args["access_token"]);
        }
        return HttpRuntime.Cache["access_token"].ToString();
}

private Dictionary GetOauthTokens(string code)
{
        Dictionary tokens = new Dictionary();

        string clientId = "0123456789";
        string redirectUrl = "http://www.abc.com/oauth/oauth-redirect.aspx";
        string clientSecret = "a1a2a3a4a5a6a7a8a9a0";
        string scope = "read_friendlists,user_status,publish_stream,user_about_me,offline_access";

        string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&client_secret={2}&code={3}&scope={4}", clientId, redirectUrl, clientSecret, code, scope);

        HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
        {
            StreamReader reader = new StreamReader(response.GetResponseStream());

            string retVal = reader.ReadToEnd();

            foreach (string token in retVal.Split('&'))
            {
                tokens.Add(token.Substring(0, token.IndexOf("=")), token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
            }
        }
        return tokens;
}

2 回答

  • 0

    当用户访问您的应用程序时,您需要对其进行身份验证(听起来就像您一样) . 在该身份验证过程中,您可以请求您的应用所需的权限,并且用户可以将这些权限授予您的应用(听起来这个步骤很少) . 不确定您正在使用什么来开发您的应用程序,但快速搜索授予Facebook权限应该为您提供一些资源来使用 . Facebook SDK有内置的方法来请求这些额外的权限,所以如果你使用其中一个,你应该处于良好的状态 .

  • 0

    最后,我永远无法使身份验证工作 . 一个可行的解决方法 - 以及我为客户实施解决方案的方式 - 是将状态更新通过电子邮件发送到Facebook帐户 . 显然,每个Facebook帐户都有一个秘密电子邮件地址,可用于通过电子邮件发送状态更新 . 工作一种享受 .

相关问题