Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Oauth2 not able to connect

Hey I am trying to get authorized via Oauth2 using PHP, I keep getting the following response:

 

array(3) { ["result"]=> array(1) { ["error"]=> array(4) { ["message"]=> string(80) "An active access token must be used to query information about the current user." ["type"]=> string(14) "OAuthException" ["code"]=> int(2500) ["fbtrace_id"]=> string(11) "D4ijq9xa+/p" } } ["code"]=> int(400) ["content_type"]=> string(31) "application/json; charset=UTF-8" } array(1) { ["error"]=> array(4) { ["message"]=> string(80) "An active access token must be used to query information about the current user." ["type"]=> string(14) "OAuthException" ["code"]=> int(2500) ["fbtrace_id"]=> string(11) "D4ijq9xa+/p" } }

I am not sure what I am doing wrong, I have the app setup and set to server side in dev.fitbit.com

 

 

but I am not sure what I am doing wrong, here is my PHP code

 

<?php
require('cgi-bin/OAuth2/Client.php');
require('cgi-bin/OAuth2/GrantType/IGrantType.php');
require('cgi-bin/OAuth2/GrantType/AuthorizationCode.php');

const CLIENT_ID     = '******';
const CLIENT_SECRET = '**********************************';

const REDIRECT_URI           = 'http://robertpallister.com/apps/openfit/sync_fitbit.php';
const AUTHORIZATION_ENDPOINT = 'https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=22857R&redirect_uri=http%3A%2F%2Frobertpallister.com%2Fapps%2Fopenfit%2Fsync_fitbit.php&scope=activity&expires_in=604800';
const TOKEN_ENDPOINT         = 'https://api.fitbit.com/oauth2/token';

$client = new OAuth2\Client(CLIENT_ID, CLIENT_SECRET);
if (!isset($_GET['code']))
{
    $auth_url = $client->getAuthenticationUrl(AUTHORIZATION_ENDPOINT, REDIRECT_URI);
    header('Location: ' . $auth_url);
    die('Redirect');
}
else
{
    $params = array('code' => $_GET['code'], 'redirect_uri' => REDIRECT_URI);
    $response = $client->getAccessToken(TOKEN_ENDPOINT, 'authorization_code', $params);
    parse_str($response['result'], $info);
    $client->setAccessToken($info['access_token']);
    $response = $client->fetch('https://graph.facebook.com/me');
    var_dump($response, $response['result']);
}

?>

Any suggestions?

 

Thanks in advance! And sorry if this is a very basic mistake.

 

 

Best Answer
0 Votes
1 REPLY 1

@RobertN64 I get this when trying to auth your app:

 

Warning: parse_str() expects parameter 1 to be string, array given in /home/robertpallister/websites/robertpallister/apps/openfit/sync_fitbit.php on line 24
array(3) { ["result"]=> array(1) { ["error"]=> array(4) { ["message"]=> string(80) "An active access token must be used to query information about the current user." ["type"]=> string(14) "OAuthException" ["code"]=> int(2500) ["fbtrace_id"]=> string(11) "AI37GewSHA+" } } ["code"]=> int(400) ["content_type"]=> string(31) "application/json; charset=UTF-8" } array(1) { ["error"]=> array(4) { ["message"]=> string(80) "An active access token must be used to query information about the current user." ["type"]=> string(14) "OAuthException" ["code"]=> int(2500) ["fbtrace_id"]=> string(11) "AI37GewSHA+" } }

The message here seems to point to line 24.

 

Additionally, I think you need to change this line:

$response = $client->fetch('https://graph.facebook.com/me');

 

 

Andrew | Community Moderator, Fitbit

What motivates you?

Best Answer
0 Votes