PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 6, 2022

[FIXED] Retrieving user information with access token - Facebook developer

 January 06, 2022     access-token, facebook, facebook-php-sdk, php     No comments   

Issue

I'm developing a Facebook application, and I want to retrieve some of the user's information on a side server while they are using the application.

In order to make that possible, I store the users access token in my database and pass it to the other server.

However, I am not sure how to use the access token to retrieve the user information. I am using the PHP SDK, and here is the usual code:

require '../src/facebook.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => '',
  'secret' => '',
));

// Get User ID
$user = $facebook->getUser();

Where can I declare the access token?


Solution

It's very simple. If you enter a url like https://graph.facebook.com/me?access_token=theuseraccesstoken (in your browser) you will receive a json file with the user information.

I'm pretty sure the facebook php sdk have a built in mechanism to do that (I'm a c# coder), but you are looking in the wrong place, because no api key or secret is necessary to access user information using a access token.

UPDATE1:

I think it works like this in the sdk

$facebook->setAccessToken($access_token);
$user = $facebook->getUser();

UPDATE2:

Or like this

$user = $facebook->api('me?access_token='.$access_token);


Answered By - lolol
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing