set_endpoint( 'authorize', 'https://foursquare.com/oauth2/authenticate', 'GET' ); $this->set_endpoint( 'access_token', 'https://foursquare.com/oauth2/access_token', 'GET' ); $this->set_endpoint( 'self', 'https://api.foursquare.com/v2/users/self', '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; } function basic_ui_intro() { echo '

' . __( "If you haven't already, you'll need to create a new app at Foursquare. You should only need to worry about these settings:", 'keyring' ) . '

'; echo '
    '; echo '
  1. ' . __( "Your app name: enter whatever you like, maybe your website's name?", 'keyring' ) . '
  2. '; echo '
  3. ' . sprintf( __( "Download / welcome page url: just enter your website's URL, %s", 'keyring' ), get_bloginfo( 'url' ) ) . '
  4. '; echo '
  5. ' . sprintf( __( "Redirect URI(s): Copy-paste this, %s", 'keyring' ), Keyring_Util::admin_url( 'foursquare', array( 'action' => 'verify' ) ) ) . '
  6. '; echo '
  7. ' . __( "New users can connect via the web: check the box", 'keyring' ) . '
  8. '; echo '
'; echo '

' . __( "Once you've saved those changes, copy the Client id value into the API Key field, and the Client secret value into the API Secret field and click save (you don't need an App ID value for Foursquare).", 'keyring' ) . '

'; } function build_token_meta( $token ) { $token = new Keyring_Access_Token( $this->get_name(), $token['access_token'], array() ); $this->set_token( $token ); $res = $this->request( $this->self_url, array( 'method' => $this->self_method ) ); if ( Keyring_Util::is_error( $res ) ) { $meta = array(); } else { $meta = array( 'user_id' => $res->response->user->id, 'first_name' => $res->response->user->firstName, 'last_name' => $res->response->user->lastName, 'picture' => $res->response->user->photo->prefix . '300x300' . $res->response->user->photo->suffix, ); } return apply_filters( 'keyring_access_token_meta', $meta, 'foursquare', $token, $res, $this ); } function get_display( Keyring_Access_Token $token ) { $meta = $token->get_meta(); return trim( $meta['first_name'] . ' ' . $meta['last_name'] ); } function request( $url, array $params = array() ) { $url = add_query_arg( array( 'v' => self::API_VERSION ), $url ); return parent::request( $url, $params ); } } add_action( 'keyring_load_services', array( 'Keyring_Service_Foursquare', 'init' ) );