0

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?

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
Hemadeus
  • 472
  • 8
  • 20
  • It looks like you're trying to use an app access token to manage a page - you need to use a page access token for that - does it work with a page access token? – Igy Apr 11 '14 at 04:53
  • it work with a page access token, but I would have love to be able to give access to my page to my app. So I don't need a admin token store in my site, and renew it ... – Hemadeus Apr 11 '14 at 13:26

2 Answers2

1

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

Community
  • 1
  • 1
Tobi
  • 31,405
  • 8
  • 58
  • 90
  • Exactly what I was going to do, but in the documentation they said that extended token could be delete if the admin user log out, so I don't want the app to stop working normally if the admin user log out... anyway it's the only way I found right now – Hemadeus Apr 11 '14 at 13:19
  • mmm I may have misread, well that's good news. I would still need to keep an admin token in my app and renew it each 15 days or so – Hemadeus Apr 11 '14 at 13:28
  • Have you read my answer thoroughly? The Token you will receive is NON-EXPIRING! – Tobi Apr 11 '14 at 13:35
0

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.

Community
  • 1
  • 1
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
  • I'm able to add an event to my page, but the user that add the event need to be an admin, I don't want everyone to be admin of my page so I need to use the admin token everytime. That would not be a problem if in the documentation they are talking about extended token can be not valid anymore if the user ( admin in this case) log out, or any other reason – Hemadeus Apr 11 '14 at 13:24
  • That's the incorrect statement: `extended token can be not valid anymore if the user ( admin in this case) log out,`, if you have a valid access token, you can make calls using that token. So, if your app demands that any user can add events to YOUR page, extend your token once and use that of all the users. – Sahil Mittal Apr 11 '14 at 13:29
  • @skatnick: I already described everything you need to do in my answer... I don't really see where the problem is. – Tobi Apr 11 '14 at 13:38
  • 1
    @skatanick, here I've explained clearly how to get the never expiring token if you want it to use directly in your app: http://stackoverflow.com/a/23004308/1343690. – Sahil Mittal Apr 11 '14 at 13:39
  • Sometimes SO is hard... @Sahil – Tobi Apr 11 '14 at 13:40
  • Just calm down, I'm working I was not in front of my pc, and you were right I said that my last statement about the extended token was not right. I know how to created extended token. Anyway, thanks and no reason to be rude – Hemadeus Apr 11 '14 at 13:46