wishlist: 500px
-
I’ve tried to extend the plugin with 500px, but the 500px API seems to be extremely picky and hard to deal with.
In case someone had already dealt with 500px and now what should be done in order to get it working ( at least get pass the request token step ), it’d be very happy. I’m not able to get anything but a 401 out from their services with the following implementation.
The official 500px API documentation is located on Github.
<?php /** * 500px service definition for Keyring. */ class Keyring_Service_500px extends Keyring_Service_OAuth1 { const NAME = '500px'; const LABEL = '500px'; function __construct() { parent::__construct(); if ( ! KEYRING__HEADLESS_MODE ) { add_action( 'keyring_500px_manage_ui', array( $this, 'basic_ui' ) ); add_filter( 'keyring_500px_basic_ui_intro', array( $this, 'basic_ui_intro' ) ); } $this->authorization_header = true; $this->authorization_realm = 'api.500px.com'; $this->set_endpoint( 'request_token', 'https://api.500px.com/v1/oauth/request_token', 'GET' ); $this->set_endpoint( 'authorize', 'https://api.500px.com/v1/oauth/authorize', 'GET' ); $this->set_endpoint( 'access_token', 'https://api.500px.com/v1/oauth/access_token', 'GET' ); $this->set_endpoint( 'authenticate', 'https://api.500px.com/v1/oauth/authorize', 'GET' ); $creds = $this->get_credentials(); $this->app_id = $creds['app_id']; $this->key = $creds['key']; $this->secret = $creds['secret']; $this->consumer = new OAuthConsumer( $this->key, $this->secret, $this->callback_url ); $this->signature_method = new OAuthSignatureMethod_HMAC_SHA1; $this->requires_token( true ); } function basic_ui_intro() { echo '<p>' . sprintf( __( 'To connect to 500px, you\'ll need to <a href="%s">create an application at 500px.com</a>.', 'keyring' ), 'https://500px.com/settings/applications' ) . '</p>'; echo '<p>' . __( "Once you've created your app, enter the API <strong>Consumer Key</strong> and <strong>Consumer Secret</strong> below.", 'keyring' ) . '</p>'; } function parse_response( $response ) { return json_decode( $response ); } function build_token_meta( $token ) { // Set the token so that we can make requests using it $this->set_token( new Keyring_Access_Token( $this->get_name(), new OAuthToken( $token['oauth_token'], $token['oauth_token_secret'] ) ) ); $response = $this->request( "https://api.500px.com/v1/users", 'GET' ); if ( Keyring_Util::is_error( $response ) ) { $meta = array(); } else { $meta = array( 'user_id' => $token['user']['id'], 'username' => $token['user']['username'], 'name' => $token['user']['fullname'], 'picture' => $token['user']['userpic_https_url'], ); } return apply_filters( 'keyring_access_token_meta', $meta, '500px', $token, $response, $this ); } function get_display( Keyring_Access_Token $token ) { return $token->get_meta( 'username' ); } } add_action( 'keyring_load_services', array( 'Keyring_Service_500px', 'init' ) );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘wishlist: 500px’ is closed to new replies.