6

This is a rather infuriating problem. We had code that was working perfectly fine for months and now, all of the sudden, it doesn't. The code just used this url to grab the wall posts we were making on our fan page and showed them on our site. http://graph.facebook.com/[our number]/feed?limit=10

Now it doesn't work and I've spent a ridiculous number of hours sifting through search results on this issue. Unfortunately, everything I find seems to be referring to Facebook apps and not fan pages. I can't stop seeing how I need to authenticate it using my secret key, but I can't find anything that shows me what my fan page's secret key is or if one even exists. I can't, for the life of me, get this thing working and I can't figure out why it just randomly stopped working in the first place.

Here's the error we get:

{
   "error": {
      "type": "OAuthException",
      "message": "An access token is required to request this resource."
   }
}

EDIT: So thanks much to Frank Farmer for finding that post, the problem is needing an access token, which I can't find ANY solution to getting ANYWHERE.

4 Answers 4

3

The way that I was able to do this was by:

  • Creating a new facebook application
  • Logged into Facebook with the user that is an admin for the Facebook Page
  • Opened up a request for permissions for the application

    https://www.facebook.com/dialog/oauth?client_id='the_application_id'&redirect_uri=http://your_redirect_uri/&scope=email,read_stream,user_birthday,user_about_me,user_likes,read_stream,user_education_history,user_work_history,user_groups,user_hometown,user_religion_politics,user_location,user_online_presence,user_relationships,user_status,user_website,read_friendlists,offline_access,manage_pages,ads_management,publish_stream

Your redirect URI MUST match what you have set into the application settings in your facebook application.

  • I basically granted access to everything for this application, the main thing you need to make sure of is 'manage_pages'

-After that you will need to copy the 'code=xxxxxx' portion of the link that you are forwarded onto after accepting the permissions request. You can THEN request an access_code for the user, once you have that, you can get the Facebook page posts that the user is an admin to.

https://graph.facebook.com/oauth/access_token?client_id='the_application_id'&redirect_uri=http://your_redirect_uri/&client_secret='the_code_from_above'
  • It will then respond with an access code!

https://graph.facebook.com/feed?access_token='your_access_token'

Below is some sample code you can use with the PHP facebook SDK:

define('APP_ID', 'your_app_id');
        define('APP_API_KEY', 'your_app_api_key');
        define('APP_SECRET', 'your_app_secret');

        $fb = new Facebook(array(
            'appId' => APP_ID,
            'secret' => APP_SECRET,
            'cookie' => false
        ));

        $fb_user_id   = 'user_id_of_person_that_has_page_admin_rights';
        $access_token = urlencode('your_access_token_you_received');

        try {

            $user = $fb->api('/'.$fb_user_id,'GET',array('access_token'=>$access_token));
            $accounts = $fb->api('/'.$fb_user_id.'/accounts','GET',array('access_token'=>$access_token));

        } catch (FacebookApiException $e) {

            echo $e->getMessage();

        }

        echo "<strong>User Details:</strong><br />";
        foreach($user as $key => $value){
            echo ucwords(str_replace("_"," ",$key)).": ".$value."<br />";
            $fb->api('/feed','POST',array('access_token'=>$access_token,'id'=>$user_id,'message'=>'Add a post to the user's wall'));
        }

        echo "<br /><strong>Accounts Details:</strong><br />";
        foreach($accounts['data'] as $account){
            foreach($account as $key => $value){
                echo ucwords(str_replace("_"," ",$key)).": ".$value."<br />";
            }

            try {

                $posts = $fb->api('/'.$account['id'].'/posts','GET',array('access_token'=>$account['access_token']));

            } catch (FacebookApiException $e) {

                echo $e->getMessage();

            }

            echo "<br /><strong>-- Posts for this account:</strong><br />";

            foreach($posts['data'] as $post){
                foreach($post as $key => $value){
                    echo ucwords(str_replace("_"," ",$key)).": ".$value."<br />";
                }
                echo "<br />";
            }

        }
6
  • 1
    That.... is.... insane. Why in god's name would FB make you go through that unbelievable runaround... Hold on I'm trying it now.
    – Cyprus106
    Jun 6, 2011 at 18:41
  • I got as far as "-After that you will need to copy the 'code=xxxxxx' " I copied the insanely long code and put it in the client_secret= portion of the URL you had, but it says error validating client secret. Any insights?
    – Cyprus106
    Jun 6, 2011 at 18:57
  • @Cyprus106 Read over this page: link
    – Nick
    Jun 6, 2011 at 22:02
  • But guys, every single doc I keep getting and seeing, every link shows how to do this for an application, not a fan page!! And the two aren't interchangeable. I got as far as plugging in the code= that you so kindly suggested, but it always says "error validating client secret."
    – Cyprus106
    Jun 8, 2011 at 14:11
  • 1
    Awesome, glad you were able to get it working! I think I had the same issue... your final comment about the missing '/' seems all too familiar...
    – Nick
    Jun 20, 2011 at 23:44
2

Yeah, it requires a token now. They announced this via their blog.

http://developers.facebook.com/blog/post/509/

Breaking change: Graph API PROFILE_ID/feed and PROFILE_ID/posts requires access_token

The Graph API PROFILE_ID/feed/ for a Page, Application, User or Group and PROFILE_ID/posts for a Page or User will now require a vaild access_token to access the wall or posts of the corresponding object (where previously no access_token was required).

Looks like they only gave a week notice.

You should subscribe to the RSS feed for their dev blog. They pull stuff like this all the time, although usually they give a little more notice.

2
  • Thanks a lot. Sure enough that's why it broke. I guess my REAL problem is I can't find ANYWHERE that tells me where I can GET my access_token for my own fan page!
    – Cyprus106
    Jun 6, 2011 at 18:17
  • Did you solved the problem? Where can I obtain access_token for own fan page?
    – Lari13
    Feb 16, 2012 at 20:05
0

After you have your personal access token, run:

https://graph.facebook.com/me/accounts?access_token=token

where 'token' is your access token. This will show you all the access tokens for the pages you have access to. Now use that page access token to post to:

'/page_username_id/feed'

where page_username_id is either the page id or the url username.

Hope this helps. Skye

0

The URL

https://graph.facebook.com/oauth/access_token?client_id='the_application_id'&redirect_uri=http://your_redirect_uri/&client_secret='the_code_from_above'

is not true. the Client Secret is your App Secret. You need a extra argument, for example:

https://graph.facebook.com/oauth/access_token?client_id=[YOUR-APP-ID]&redirect_uri=http://your-uri(like in the app config)/&client_secret=[your-app-secret]&code=[code-from-above]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.