How can my facebook application post message to a wall?

Posted by Thomas Dekiere on Stack Overflow See other posts from Stack Overflow or by Thomas Dekiere
Published on 2011-04-16T14:51:53Z Indexed on 2011/11/21 17:50 UTC
Read the original article Hit count: 260

i already found out how to post something to a wall with the graph api on behalf of the facebook user. But now i want to post something in the name of my application.

Here is how i'm trying to do this:

protected void btn_submit_Click(object sender, EventArgs e)
{

    Dictionary<string, string> data = new Dictionary<string, string>();
    data.Add("message", "Testing");
    // i'll add more data later here (picture, link, ...)
    data.Add("access_token", FbGraphApi.getAppToken());
    FbGraphApi.postOnWall(ConfigSettings.getFbPageId(), data);

}

FbGraphApi.getAppToken()

// ...
private static string graphUrl = "https://graph.facebook.com";
//...

public static string getAppToken() {
    MyWebRequest req = new MyWebRequest(graphUrl + "/" + "oauth/access_token?type=client_cred&client_id=" + ConfigSettings.getAppID() + "&client_secret=" + ConfigSettings.getAppSecret(), "GET");
    return req.GetResponse().Split('=')[1];
}

FbGraphApi.postOnWall()

public static void postOnWall(string id, Dictionary<string,string> args)
    {
        call(id, "feed", args);
    }

FbGraphApi.call()

private static void call(string id, string method, Dictionary<string,string> args )
{
    string data = "";
    foreach (KeyValuePair<string, string> arg in args)
    {

        data += arg.Key + "=" + arg.Value + "&";

    }

    MyWebRequest req = new MyWebRequest(graphUrl +"/" + id + "/" + method, "POST", data.Substring(0, data.Length - 1));


    req.GetResponse();  // here i get: "The remote server returned an error: (403) Forbidden."
}

Does anyone see where this i going wrong? I'm really stuck on this.

Thanks!

© Stack Overflow or respective owner

Related posts about facebook

Related posts about post