dev-master
9999999-dev https://github.com/huitiemesens/withingsWithings api library.
Apache-2.0
The Requires
- php >=5.3.0
- huitiemesens/oauth dev-master
api withings
Withings api library.
Basic wrapper for the OAuth-based Withings REST API. See oauth.withings.com for details on their OAuth implementation., (*1)
Both this library and the Withings API are in beta., (*2)
This library does not require the PHP OAuth extension. It should work on any server with PHP >= 5.3., (*3)
This bundle allows you to get notification from withings or grab manually informations., (*4)
This package is installable with composer: "huitiemesens/withings": "dev-master", (*5)
You need a consumer key and secret. You can obtain them by registering an application at http://oauth.withings.com., (*6)
Simple, but full OAuth workflow example with database integration:, (*7)
$factory = new \Withings\ApiGatewayFactory; $factory->setCallbackURL( $withings_callback_url ); $factory->setCredentials( $withings_consumer_key , $withings_consumer_secret ); // these variables come from database $adapter = new \OAuth\Common\Storage\Session(); $factory->setStorageAdapter($adapter); $auth_gateway = $factory->getAuthenticationGateway(); if (isset($_GET['oauth_token']) && isset($_GET['oauth_verifier'])) { $auth_gateway->authenticateUser($_GET['oauth_token'], $_GET['oauth_verifier']); $storage = $factory->getStorageAdapter(); $token = $storage->retrieveAccessToken('Withings'); $this->getUser()->setWithingsToken( $token->getRequestToken() ) ; // Your user entity must have a WithingsToken column $this->getUser()->setWithingsTokenSecret( $token->getRequestTokenSecret() ); // Your user entity must have a WithingsTokenSecret column $this->getUser()->setWithingsId( $_GET['user_id'] ); // Your user entity must have a WithingsUserId column $em->persist( $this->getUser() ); $em->flush(); }else { $auth_gateway->initiateLogin(); }
public function withingsGetProfile() { $factory = new \Withings\ApiGatewayFactory; $factory->setCallbackURL( $withings_callback_url ); $factory->setCredentials( $withings_consumer_key , $withings_consumer_secret ); // these variables come from database $token = new \OAuth\OAuth1\Token\StdOAuth1Token(); $token->setRequestToken( $user->getWithingsToken() ); // user credentials $token->setRequestTokenSecret( $user->getWithingsTokenSecret() ); // user credentials $token->setAccessToken( $user->getWithingsToken() ) // user credentials; $token->setAccessTokenSecret( $user->getWithingsTokenSecret() ); // user credentials $adapter = new \OAuth\Common\Storage\Memory(); $adapter->storeAccessToken('Withings', $token); $factory->setStorageAdapter($adapter); $UserGateway = $factory->getUserGateway(); $profile = $UserGateway->getProfile( $user->getWithingId() ); // user withings id print_r ( $profile ) ; }
Thanks to popthestack/fitbitphp for the code structure., (*8)
Withings api library.
Apache-2.0
api withings