开发者

How to set Facebook App Settings

I have written an ASP.NET page for a customer which uses the C# Facebook API to post to Facebook.

// Post to Facebook.

// Build the Arguments. Dictionary postArgs = new Dictionary(); postArgs["message"] = "Hello World!";

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

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

I registered the application http://developers.facebook.com/setup/ using my personal Facebook account to test the integration.

Under the section 'Select how your app integrates with Facebook' I chose 'Website' and entered the Site URL.

When I view the App under my Account Settings it has the following 'App Settings': Access my basic information; Access my profiel information; Post to Facebook as me; Access my data anytime.

Everything works great.

I have set up the same application using my customer's Facebook account. I changed the Client ID and the Client Secret to the new details.

It no longer works.

When I view the App under my customer's Account Settings it doesn't have any of the 'App Settings' listed above.

My 'App Settings' allows the App greater access to my Facebook Account compared to my customer's 'App Setttings' - which I guess is why it fails to post to my customer's Facebook Account.

Unfortunately, I do not recall explicitly setting these 'App Settings' on my Facebook Account. I also can't seem to find anywhere on Facebook where I can set these 'App Settings' on my customer's account.

Can someone please help / direct me please.

Thanks in advance.

Kind Regards

Walter

Update:

Here is my code:

First of all I authenticate:

// 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));

Next the oauth/oauth-redirect.aspx page is performed.

Here is the code-behind of 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;
}


When a user accesses your app you need them to authenticate (Sounds like you are). During that authentication process you can request permissions that your app requires and they user can grant those permissions to your app (Sounds like this step is missing). Not sure what you're using to develop your app but a quick search for grant facebook permissions should bring you up some resources to work with. The Facebook SDK's have built in methods for requesting these additional permissions so if you're using one of them you should be in good shape.


In the end I could never get the authentication to work. A workable workaround - and the way I implemented the solution for my client - was to email the status update to the Facebook account. Apparently every Facebook account has a secret email address that can be used to email Status updates. Works a treat.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜