2017 © Pedro Peláez
 

library withings

Withings api library.

image

huitiemesens/withings

Withings api library.

  • Wednesday, March 30, 2016
  • by huitiemesens
  • Repository
  • 5 Watchers
  • 0 Stars
  • 267 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

WithingsPHP

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)

Installation

This package is installable with composer: "huitiemesens/withings": "dev-master", (*5)

Usage

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)

  • App Authorization

$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(); }
  • Retrieving user profile informations

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)

The Versions

30/03 2016

dev-master

9999999-dev https://github.com/huitiemesens/withings

Withings api library.

  Sources   Download

Apache-2.0

The Requires

 

api withings