Ejemplo n.º 1
0
  public AuthTokenObject getAccessToken(String verifier) {
    try {
      this.provider.retrieveAccessToken(this.consumer, verifier);
    } catch (OAuthMessageSignerException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    } catch (OAuthNotAuthorizedException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    } catch (OAuthExpectationFailedException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    } catch (OAuthCommunicationException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }

    AuthTokenObject access = new AuthTokenObject();
    access.tokenKey = this.consumer.getToken();
    access.tokenSecret = this.consumer.getTokenSecret();

    return access;
  }
Ejemplo n.º 2
0
  public String getAuthorizationURL(String callbackURL) {

    String authUrl = null;
    try {
      authUrl = this.provider.retrieveRequestToken(this.consumer, callbackURL);
    } catch (OAuthMessageSignerException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    } catch (OAuthNotAuthorizedException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    } catch (OAuthExpectationFailedException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    } catch (OAuthCommunicationException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
    this.requestKey = this.consumer.getToken();
    this.requestSecret = this.consumer.getTokenSecret();

    return authUrl;
  }
Ejemplo n.º 3
0
 /**
  * Returns the URL to direct the user to so their account can approve the application to access
  * user data
  *
  * @return
  */
 public String getAuthenticationUrl() {
   String authUrl = "";
   try {
     authUrl = this.provider.retrieveRequestToken(this.consumer, "neoseeker-app://oauth");
   } catch (OAuthMessageSignerException e) {
     Log.e("NeoAPI", "OAuthMessageSignerException: " + e.getMessage());
   } catch (OAuthNotAuthorizedException e) {
     Log.e("NeoAPI", "OAuthNotAuthorizedException: " + e.getMessage());
   } catch (OAuthExpectationFailedException e) {
     Log.e("NeoAPI", "OAuthExpectationFailedException: " + e.getMessage());
   } catch (OAuthCommunicationException e) {
     Log.e("NeoAPI", "OAuthCommunicationException: " + e);
   }
   return authUrl;
 }
Ejemplo n.º 4
0
    @Override
    protected String doInBackground(String... params) {
      String message = null;
      String verifier = params[0];
      try {
        // Get the token
        Log.d(TAG, "mConsumer: " + mConsumer);
        Log.d(TAG, "mProvider: " + mProvider);
        mProvider.retrieveAccessToken(mConsumer, verifier);
        String token = mConsumer.getToken();
        String tokenSecret = mConsumer.getTokenSecret();
        mConsumer.setTokenWithSecret(token, tokenSecret);

        Log.d(
            TAG,
            String.format(
                "verifier: %s, token: %s, tokenSecret: %s", verifier, token, tokenSecret));

        // Store token in prefs
        prefs.edit().putString("token", token).putString("tokenSecret", tokenSecret).commit();

        // Make a Twitter object
        oauthClient = new OAuthSignpostClient(OAUTH_KEY, OAUTH_SECRET, token, tokenSecret);
        twitter = new Twitter("MarkoGargenta", oauthClient);

        Log.d(TAG, "token: " + token);
      } catch (OAuthMessageSignerException e) {
        message = "OAuthMessageSignerException";
        e.printStackTrace();
      } catch (OAuthNotAuthorizedException e) {
        message = "OAuthNotAuthorizedException";
        e.printStackTrace();
      } catch (OAuthExpectationFailedException e) {
        message = "OAuthExpectationFailedException";
        e.printStackTrace();
      } catch (OAuthCommunicationException e) {
        message = "OAuthCommunicationException";
        e.printStackTrace();
      }
      return message;
    }
Ejemplo n.º 5
0
 /**
  * 获得AccessToken
  *
  * @param intent
  * @return UserInfo
  */
 public User getAccessToken(Intent intent) {
   Uri uri = intent.getData();
   // 处理获取返回的oauth_verifier参数
   String verifier = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER);
   try {
     httpOauthprovider.setOAuth10a(true);
     httpOauthprovider.retrieveAccessToken(httpOauthConsumer, verifier);
   } catch (OAuthMessageSignerException ex) {
     ex.printStackTrace();
   } catch (OAuthNotAuthorizedException ex) {
     ex.printStackTrace();
   } catch (OAuthExpectationFailedException ex) {
     ex.printStackTrace();
   } catch (OAuthCommunicationException ex) {
     ex.printStackTrace();
   }
   SortedSet<String> user_id = httpOauthprovider.getResponseParameters().get("user_id");
   String userToken = httpOauthConsumer.getToken();
   String userSecret = httpOauthConsumer.getTokenSecret();
   User user = new User(user_id.first(), userToken, userSecret);
   return user;
 }
Ejemplo n.º 6
0
 @Override
 protected String doInBackground(Void... params) {
   String authUrl;
   String message = null;
   try {
     authUrl = mProvider.retrieveRequestToken(mConsumer, OAUTH_CALLBACK_URL);
     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl));
     startActivity(intent);
   } catch (OAuthMessageSignerException e) {
     message = "OAuthMessageSignerException";
     e.printStackTrace();
   } catch (OAuthNotAuthorizedException e) {
     message = "OAuthNotAuthorizedException";
     e.printStackTrace();
   } catch (OAuthExpectationFailedException e) {
     message = "OAuthExpectationFailedException";
     e.printStackTrace();
   } catch (OAuthCommunicationException e) {
     message = "OAuthCommunicationException";
     e.printStackTrace();
   }
   return message;
 }