Hemadeus
Hemadeus

Reputation: 472

Facebook Application publish on facebook page

I want my facebook application to create events in my facebook page. Everyone that use my application will be able to publish events to my facebook page, so I don't want to give admin or contributor to everyone, I want my web app ( appId + secret code) to have the rights to publish

When I'm trying this:

client.AccessToken = "{app-id}|{app-secret}";
dynamic result = client.Post("/{page-id}/events", new{
                    name = "testEvent",
                    start_time = "2014-04-11T19:00:00-0700",
                    end_time = "2014-04-11T20:00:00-0700",
                }
);

I received this error

{
  "error": {
    "type": "Exception", 
    "message": "You must be an admin of the specified page to perform the requested action.", 
    "code": 1373019
  }
}

Any idea?

Upvotes: 0

Views: 269

Answers (2)

Tobi
Tobi

Reputation: 31479

You should do the following:

  1. Get a Page Access Token via the /me/accounts endpoint (the logged in User must be the administrator of this page). You can do this via https://developers.facebook.com/tools/explorer?method=GET&path=me%2Faccounts Be sure that you have requested the manage_pages, create_event and publish_stream permissions beforehand.

  2. Exchange your short-lived Page Access Token to a non-expiring one as described here: What are the Steps to getting a Long Lasting Token For Posting To a Facebook Fan Page from a Server

  3. Use the newly generated Page Access Token in your App

Upvotes: 1

Sahil Mittal
Sahil Mittal

Reputation: 20753

The token that you are using is called the App Access Token, and according to the documentation of /{page-id}/events, it says:

An page access token for the page with create_event permission is required.

Now to get the page access token-

  1. First you need to re-authenticate the user (by calling the facebook login/auth again) by adding the permissions:

    • manage_pages, required for getting the page access token
    • create_event, required for creating an event
  2. Then make the call:

    \GET /{page-id}?fields=access_token, you will get the page access token in response.

Use the token generated in step-2 and make the call you are making, then it will be a success.

(If required, you can also extend this page access token that will never expire- see here)
Learn more about access tokens here.

Upvotes: 0

Related Questions