Zn4rK / php-withings

PSR-FIG Compatible Withings Body metrics Services API written in PHP.
17 stars 14 forks source link

key names #2

Closed RomainGoncalves closed 10 years ago

RomainGoncalves commented 10 years ago

Hey again.

Was there an update of the API recently? Coz there's something I dont understand. When I follow your code, I get redirected to Withings, I log in, then get redirected to my page, not worries there.

But from Withing I receive this array:

array(3) {
  ["userid"]=>
  string(7) "XXXXX" //normal number
  ["oauth_token"]=>
  string(61) "49dcd9819fbfd610dee730f4d0bc32515633433e470fe6229ef3319421bd7"
  ["oauth_verifier"]=>
  string(12) "dNesjYPowBLZ"
}

but then when I get redirected I get an error saying that the Token.php file requires another sort of array, containing access_token and secret. But I don't have that anywhere else.

Can you tell me if I'm doing something wrong, or has the API changed?

Cheers

BTW: Im using your example code.

Zn4rK commented 10 years ago

I managed to get everything working last night when I updated. I can just assume that you are not saving the temporary tokens used to validate the real tokens. This is done with PHP sessions in my example code.

Withings API has a pretty stupid implementation of oauth1, and I'm using Guzzle and chrisnharvey's oauth1 client to handle the logic for me, and that's why the key names varies. Withings does not follow the specification.

Can you provide me with an error message?

RomainGoncalves commented 10 years ago

The error is: Required option not passed: access_token

I save the values that come back from the server in database, using a resource in Laravel 4.1

Zn4rK commented 10 years ago

Do the error show on which line they where throwed?

If you look in the example code, you can see that the first thing that happends is the redirect. But right before the redirect, we save the request-tokens in a temporary SESSION (to maintain the data between page loads), this is not the session you would like to save in the database.

If you, for some reason do not save the temporary requestTokens before the redirect, withings can not validate your request and you will not receive the permanent tokens.

The line, $tokens = $oauth->getUserTokens(); is the one you would like to save. These are permanent, and do not change until the user re-authorizes your application again.

I downloaded this into a fresh installation of laravel 4.1 and tested it with my example code and everything works just fine.

RomainGoncalves commented 10 years ago

Yep you're right. I tried with exactly your code and most of all the $_SESSION array and it works. Now Im just trying to leverage Laravel's session part and it doesn't seem to work.

Anyway, I think we can close this issue for now.

Thanks