0
votes

How to add an application to a page(which I have created) through API with Publish_stream permissions?

Here is the Sequence of things I have tried sofar using app. Adding App to a page using page access token code is adding app to page apps section but unable to add "publish_stream,manage_pages" permission.

For log in to Facebook

private const string Scope = "publish_stream,manage_pages";
   FacebookClient _fb = new FacebookClient();
   var fbLoginUrl = _fb.GetLoginUrl(
                new
                {
                    client_id = AppId,
                    client_secret = Appsecret,
                    redirect_uri = RedirectUri,
                    response_type = "code",
                    scope = Scope,
                    state = state
                });

To get short lived access token

if (Request.QueryString["code"] != null)
            code = Request.QueryString["code"];
           var result = _fb.Post("oauth/access_token",
                                  new
                                  {
                                      client_id = AppId,
                                      client_secret = Appsecret,
                                      redirect_uri = RedirectUri,
                                      code = code,
                                      scope = Scope,
                                      response_type="token"
                                  });

To get long lived access token

var result1 = _fb.Post("oauth/access_token", new { client_id = AppId, client_secret = Appsecret, grant_type = "fb_exchange_token", fb_exchange_token= Session["fb_access_token"] as string });

To get Page access Token

dynamic accounts = _fb.Get("me/accounts");

Add App to a Page using Page Access Token

var sResult = _fb.Post("<PAGE-ID>/tabs",
                                                    new
                                                    {
                                                        app_id = AppId,
                                                        access_token = <PAGE ACCESS TOKEN>,
                                                        scope = Scope
                                                    });
1
What was the error message when you POSTed to /{page}/tabs ? that's the correct method of adding a tab and it seems like your code sample is correct - Igy
Well, Once the app is added to a page, Using APP Access Token I want to post a message to page feed, I get an exception:(OAuthException - #200) (#200) The user hasn't authorized the application to perform this action - user1401299
You can't use the app access token to post to a page - apps can't post in their own right - to post as the page you need the page access token you retrieved from the page admin - Igy
Well, I was successfully posted to a page once i get Page_Access_Token. But I am building an app for several department users who post messages to these pages. They do not want to log-in. Documentation says app can act on behalf of user if permission given. The above mentioned code did add app to user settings and granted permissions. But I want to app to be added to different pages which I am administering. This way app can post content. - user1401299

1 Answers

0
votes

It seems from your comments you're trying to post 'as' the app onto a page - this is not possible. You need to post using a page access token retrieved from an admin of the page, and this page access token allows you to make posts on behalf of the page. Apps cannot post 'as themselves'.