Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to specify custom fields #32

Closed
araratpoghosyan opened this issue Jan 24, 2017 · 1 comment
Closed

Unable to specify custom fields #32

araratpoghosyan opened this issue Jan 24, 2017 · 1 comment

Comments

@araratpoghosyan
Copy link

in League\OAuth2\Client\Provider\Facebook.php line 103 we have this code:

$fields = [
'id', 'name', 'first_name', 'last_name',
'email', 'hometown', 'picture.type(large){url,is_silhouette}',
'cover{source}', 'gender', 'locale', 'link', 'timezone', 'age_range'
];

I am unable to add other fields, like birthday.

Thank you.

@SammyK
Copy link
Member

SammyK commented Jan 25, 2017

Hey @araratpoghosyan! The fields you listed provide some default values that don't require extra permission to access. The oauth2-facebook package is designed to help you easily obtain an access token and then leaves it up to you to make authenticated requests however you like.

If you've requested access to a field that requires extra permissions, you can just send an authenticated request with the fields you would like to receive.

Assuming you've requested the user_birthday permission.

use League\OAuth2\Client\Provider\Facebook;
use League\OAuth2\Client\Provider\AppSecretProof;

$baseUrl = Facebook::BASE_GRAPH_URL.'v2.8';
$appSecretProof = AppSecretProof::create($config['app_secret'], $token->getToken());
$params = http_build_query([
	'fields' => 'id,name,birthday',
	'access_token' => $token->getToken(),
	'appsecret_proof' => $appSecretProof,
]);
$response = file_get_contents($baseUrl.'/me?'.$params);

// Raw JSON response from the Graph API
var_dump($response);
// Response as a plain-old PHP array
$data = json_decode($response, true);
var_dump($data);

@SammyK SammyK closed this as completed Jan 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants