Important
Direct access to providers apis is newly introduced into WSL and we are still experimenting. Things might change in upcoming releases.
Access Social APIs Developer API
1. Access through PHP code
Expect for the OpenID ones, to access any of the social networks apis, you may invoke the Hybridauth library at any point during the second phase of the authentication process (see, Authentication Process).
Note that after the user is redirected to Redirect URL
, WSL will clear the PHP session, which will interpret the connexion to the provider api and it will be no longer possible make signed api calls.
The snippets below shows how to access Twitter and Facebook apis:
function get_user_twitter_timeline( $user_id, $provider, $hybridauth_user_profile ) { if( 'Twitter' != $provider ) { return; } include_once( WORDPRESS_SOCIAL_LOGIN_ABS_PATH . '/hybridauth/Hybrid/Auth.php' ); try { $provider = Hybrid_Auth::getAdapter( 'Twitter' ); # https://dev.twitter.com/rest/reference/get/statuses/user_timeline $response = $provider->api()->get( 'https://api.twitter.com/1.1/statuses/user_timeline.json' ); } catch( Exception $e ) { echo "Ooophs, we got an error: " . $e->getMessage(); } } add_filter( 'wsl_hook_process_login_before_wp_set_auth_cookie', 'get_user_twitter_timeline', 10, 3 );
function get_post_to_user_facebook_wall( $user_id, $provider, $hybridauth_user_profile ) { if( 'Facebook' != $provider ) { return; } include_once( WORDPRESS_SOCIAL_LOGIN_ABS_PATH . '/hybridauth/Hybrid/Auth.php' ); try { $provider = Hybrid_Auth::getAdapter( 'Facebook' ); # https://developers.facebook.com/docs/graph-api/reference/v2.2/user/feed $response = $provider->api()->post( 'https://graph.facebook.com/v2.0/me/feed', array( 'message' => 'This is a test message', )); } catch( Exception $e ) { echo "Ooophs, we got an error: " . $e->getMessage(); } } add_filter( 'wsl_hook_process_login_before_wp_set_auth_cookie', 'get_post_to_user_facebook_wall', 10, 3 );
Note:
Don't forget to ask users for a permission, otherwise Facebook will give you this error (#200) The user hasn't authorized the application to perform this action
. See, Code Snippets.
2. Authentication Playground
This tool will also give you a direct access to social networks apis via a lightweight console.
Please, do not submit issues here.
This comment section is for a general question and feedback. If you want to report a bug, please refer to the Support section.