PHP SDK Demystified – Getting the Access Token

Facebook APIs are actually HTTP based requests/responses.  In order to make sure the requests are authorized, an access token is required.

After a Facebook session is built, the access token is actually of the element in the session object.

If you want to get the access token, you can use the getAccessToken() public method.  Referring to the source code of the PHP SDK, the getAccessToken is defined as:

  /**
   * Gets a OAuth access token.
   *
   * @return String the access token
   */
  public function getAccessToken() {
    $session = $this->getSession();
    // either user session signed, or app signed
    if ($session) {
      return $session['access_token'];
    } else {
      return $this->getAppId() .'|'. $this->getApiSecret();
    }
  }

For me, I seldom use this method.  This is because:

  • PHP SDK will include the current session’s access token when sending out requests. In order words, we don’t have to add this explicitly
  • As I usually test the validity of the Facebook session in the beginning of the script, I have a “$session” variable already.  So to get the access token, I simply use $session['access_token']

It is interesting to note that when the session is not available, getAccessToken() will return use a string “appID|appSecret” as the access token.  Frankly speaking, I have NOT used this “app signed access token” before. If I need to have an access token for the application (as required by some of the Facebook APIs), I simply go through the Authenticating as an Application process. Let me know if there is in fact a specific use for this “app signed access token”.

Posted in PHP SDK Demystified | Tagged | 2 Comments

How can I use the @friend_name style tagging when publishing a post via Graph API?

When I’m writing on a user’s wall in facebook.com, I can use @friend_name to have the name linked to my friend’s profile. How can I do that when publishing a post via Graph API? This question had already been answered … Continue reading

Posted in Development Tips, FAQ | Tagged , | Leave a comment

New Facebook Application Available – What is in your Friends’ Mind

A new facebook app is now available at my marketplace. It is “What is in your Friends’ Mind”! Live Demo at: http://apps.facebook.com/whatisinyourmind/ Application Features Creator an interesting photo using your friend’s profile pictures. Your friends will be tagged accordingly Photo … Continue reading

Posted in Market Place | Leave a comment

WordPress or Joomla?

As you can see, this blog is running under WordPress.  I just notice that Joomla! v1.6 is released recently. So, what are the pros and cons / major differences between these 2 products? Anyone can here?

Posted in Uncategorized | 2 Comments

PHP SDK Demystified – Getting the Current User ID

For most of the Facebook canvas applications that I have written, after instantiating the $facebook object and getting the session object by calling $facebook->getSession(), I will test the validity of the session via querying the “me” object and set it … Continue reading

Posted in PHP SDK Demystified | Tagged | 9 Comments

How can I post to the Facebook Page’s Wall by using the page name instead of my user name?

Today, there are different people asking the same question “How can I post to the Facebook Page’s Wall by using the page name instead of my user name?”. In fact, this question had already been answered in my FAQ here. … Continue reading

Posted in Facebook Dev Forum Digest, FAQ | Tagged | Leave a comment

The Best Selling Facebook App – “Question Bank – Yes/No Questions about Your Friends”

The best selling facebook app in my marketplace at this moment is the “Question Bank – Yes/No Questions about Your Friends”. Live Demo at: http://apps.facebook.com/viewonmyfriends/ Application Features: Express your view on your friends Question and Answer can be published to … Continue reading

Posted in Market Place | Leave a comment

PHP SDK Demystified – What is Signed Request?

In the last article “PHP SDK Demystified – A Closer Look at the getSession() Call“, we have learnt how the PHP SDK will try to build / load the session. At that time, we have touched on the “Signed Request”. … Continue reading

Posted in PHP SDK Demystified | Tagged | 6 Comments
Pages: Prev 1 2 3 4 5 6 7 8 9 10 11 12 13 ...22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 Next