bahuma / xing-php-sdk
A PHP wrapper for the XING api
Installs: 879
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 1
pkg:composer/bahuma/xing-php-sdk
Requires
- guzzlehttp/guzzle: ^6.1
- guzzlehttp/oauth-subscriber: ^0.3.0
This package is auto-updated.
Last update: 2023-05-26 01:34:51 UTC
README
This is a PHP Wrapper for the Xing API based on guzzle 6. It simplifies the process of authenticating and requesting permission.
Installation
The best way to install Xing SDK is through composer:
The best way to install php-sdk-for-XING is through composer:
- 
Download the composer.pharexecutable or use the installer.$ curl -sS https://getcomposer.org/installer | php
- 
add the following to your composer.json { "require": { "bahuma/xing-php-sdk": "dev-master" } } or just run $ composer require bahuma/xing-php-sdk 
- 
Run Composer: php composer.phar install
And you should be done.
Example
You can find an advanced example in the file sample.php.
I recommend open this file and then read on.
Obtaining an Access Token
To get an access token you first have to register your application. Head over to https://dev.xing.com and register yourself for a Xing application to get the consumer key/secret which you have to use with this package.
Then you have to call the following functions in this order:
- 
getRequestTokenInsert your consumer_keyand yourconsumer_secretinto the config array.Leave the tokenandtoken_secretblank.Then create a new XingSdk Object with this config. $config = [ 'consumer_key' => CONSUMER_KEY, 'consumer_secret' => CONSUMER_SECRET, 'token' => '', 'token_secret' => '', ]; $xingSdk = new XingSDK($config); Then call the function with an url where the users are being redirected to after accepting the permissions. This URL is the callback-url. $result = $xing_api->getRequestToken("http://dev.bahuma.io/xing2?page=redirect"); The function returns an array with three values. Save request_tokenandrequest_token_secrettemporary. You'll need them in the next step.Redirect the user to the authorize_url. This is the page where the user clicks "accept".
- 
getAccessTokenThis function should be executed at the callback-url. Insert your consumer_keyand yourconsumer_secretinto the config array.Insert the request_tokenandrequest_token_secretfrom the previous field into the config array.Then create a new XingSdk Object with this config. $config = [ 'consumer_key' => CONSUMER_KEY, 'consumer_secret' => CONSUMER_SECRET, 'token' => $the_temporary_saved_request_token, 'token_secret' => $the_temporary_saved_request_token_secret, ]; $xingSdk = new XingSDK($config); Then call the function using the value of the GET-Parameter oauth_verifier, which has been set by XING.$result = $xing_api->getAccessToken($_GET['oauth_verifier']); The function returns an array containing the access_tokenand theaccess_token_secretfor the user, which has logged in. Save these values in your database or somewhere else where you can access them later.
Making calls to the XING-API
Now that you have obtained an access token, you can call the API. For example let's get the profile details of the user, which has logged in.
- 
Insert your consumer_keyand yourconsumer_secretinto the config array. Insert theaccess_tokenandaccess_token_secretfrom the user, which you have saved in your database,into the config array.$config = array( 'consumer_key' => 'abc123456789xyz', 'consumer_secret' => 'abc123456789xyz', 'token' => $access_token_from_my_database, 'token_secret' => $access_token_secret_from_my_database, ); 
- 
Create a new XingSDK Object. $xingSdk = new XingSDK($config); 
- 
Get the Guzzle Client from the XingSDK Object. $xingClient = $xingSDK->getClient(); 
- 
Make the request. // "users/me" is the endpoint of the Xing-API. See https://dev.xing.com/docs/resources $response = $xingClient->get('users/me'); 
- 
Bonus: Get the request in a usable format. $beautiful_response = XingSDK::decodeResponse($response); print_r($beautiful_response); 
And that's it.
For help how to use other request methods (GET/POST/PUT/DELETE/PATCH) or send content with your request, see the Guzzle Documentation.