0

I have been trying to implement a FitBit API integration into my Laravel App for a couple of days now and getting nowhere. The only way I have managed to even get half way there is using Socialite Providers FitBit

The code I have used so far to retrieve the FitBit user profile works fine however this is useless because there is no documentation of what to do from there to get the users steps and other API data.

Routes File

Route::get('auth/fitbit', 'Auth\AuthController@newFitBit');
Route::get('auth/fitbit/callback', 'Auth\AuthController@storeFitBit');

AuthController

protected function newFitBit()
{
    return Socialite::driver('fitbit')->redirect();
}

protected function storeFitBit()
{   
    $user = Socialite::driver('fitbit')->user();
    dd($user);
}

The first function presents the FitBit permission screen as it should. When the user clicks allow to grant the app permission it redirects to the second function which currently dumps out the user object.

What I really want to know is how to use the user object to access FitBit API data for that user as there is no documentation I was wondering if anyone else has come across this issue and had a solution.

User Object Dump

User {#201 ▼
  +token: "eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0NDM3ODE2NzksInNjb3BlcyI6Indwcm8gd251dCB3c2xlIHdzZXQgd3dlaSB3YWN0IHdzb2MiLCJzdWIiOiIzTVhUS1IiLCJhdWQiOiIyMjlWWjYiLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3NfdG9rZW4iLCJpYXQiOjE0NDM3NzgwNzl9.orn5UkgmtTJ9Xfjr8G8pp6YYSIit8XJEsVmA7KXJ56U"
  +id: "3MXTKR"
  +nickname: "Mark"
  +name: "Mark Blythe"
  +email: null
  +avatar: "https://d6y8zfzc2qfsl.cloudfront.net/50ECA47F-8FCE-1607-B66E-D0D317A40F4A_profile_150_square.jpg"
  +"user": array:1 [▶]
}

Any help would be greatly appreciated.

MÖRK
  • 954
  • 11
  • 31
  • I think you might be misunderstanding what Socialite's purpose is. It's not an interface to other APIs, it just facilitates **authentication** with services that use OAuth, and from your description it seems to do that well. – Bogdan Oct 02 '15 at 09:57
  • @Bogdan Thanks for your reply. This is my first API integration with Laravel and I'm just trying to get my head around it. I need to use what Socialite has provided to get FitBit API data so will I need a separate wrapper for this? – MÖRK Oct 02 '15 at 10:03
  • You can try using [this library](https://github.com/heyitspavel/fitbitphp) which offers a lot more methods for interacting with the FitBit API. But unfortunately the documentation seems to be limited to explaining how to authenticate and get the user profile details. So for info on the rest of the methods available you'll have to check out the [source code](https://github.com/heyitspavel/fitbitphp/blob/master/fitbitphp.php). – Bogdan Oct 02 '15 at 10:12
  • I have tried using that library and a few that have been made that extend it however they all lack documentation and all of their examples don't work anymore due to not being actively maintained. I will keep looking through to see if any of it works at all. – MÖRK Oct 02 '15 at 10:19
  • If that does not work out for you, you can always handle the authentication with Socialite which will give you the security token, and the use a PHP REST client library such as [this](https://github.com/tcdent/php-restclient) to [make requests](https://dev.fitbit.com/docs/oauth2/#making-requests) to the FitBit API as described in their [developer documentaion](https://dev.fitbit.com/docs/basics/). – Bogdan Oct 02 '15 at 10:31
  • What Socialite returns is a token that needs to be exchanged for an access token. Unfortunately there isn't anything in Laravel to do this. I'm not experienced enough to make my own OAuth wrapper for Laravel which is why I was hoping there was one already made. Unless someone creates one that works I'm screwed. Thanks for your help. – MÖRK Oct 06 '15 at 14:16

0 Answers0