Ejemplo n.º 1
0
 public RequestToken getRequestToken(
     Context context, String key, String secret, String callback_url) throws WeiboException {
   Utility.setAuthorization(new RequestTokenHeader());
   WeiboParameters postParams = new WeiboParameters();
   postParams.add("oauth_callback", callback_url);
   String rlt;
   rlt = Utility.openUrl(context, Weibo.URL_OAUTH_TOKEN, "POST", postParams, null);
   RequestToken request = new RequestToken(rlt);
   this.mRequestToken = request;
   return request;
 }
Ejemplo n.º 2
0
 public AccessToken generateAccessToken(Context context, RequestToken requestToken)
     throws WeiboException {
   Utility.setAuthorization(new AccessTokenHeader());
   WeiboParameters authParam = new WeiboParameters();
   authParam.add("oauth_verifier", this.mRequestToken.getVerifier() /* "605835" */);
   authParam.add("source", APP_KEY);
   String rlt =
       Utility.openUrl(context, Weibo.URL_ACCESS_TOKEN, "POST", authParam, this.mRequestToken);
   AccessToken accessToken = new AccessToken(rlt);
   this.mAccessToken = accessToken;
   return accessToken;
 }
Ejemplo n.º 3
0
 public AccessToken getXauthAccessToken(
     Context context, String app_key, String app_secret, String usrname, String password)
     throws WeiboException {
   Utility.setAuthorization(new XAuthHeader());
   WeiboParameters postParams = new WeiboParameters();
   postParams.add("x_auth_username", usrname);
   postParams.add("x_auth_password", password);
   postParams.add("oauth_consumer_key", APP_KEY);
   String rlt = Utility.openUrl(context, Weibo.URL_ACCESS_TOKEN, "POST", postParams, null);
   AccessToken accessToken = new AccessToken(rlt);
   this.mAccessToken = accessToken;
   return accessToken;
 }
Ejemplo n.º 4
0
 /**
  * 获取Oauth2.0的accesstoken
  *
  * <p>https://api.weibo.com/oauth2/access_token?client_id=YOUR_CLIENT_ID&
  * client_secret=YOUR_CLIENT_SECRET&grant_type=password&redirect_uri=
  * YOUR_REGISTERED_REDIRECT_URI&username=USER_NAME&pasword=PASSWORD
  *
  * @param context
  * @param app_key
  * @param app_secret
  * @param usrname
  * @param password
  * @return
  * @throws WeiboException
  */
 public Oauth2AccessToken getOauth2AccessToken(
     Context context, String app_key, String app_secret, String usrname, String password)
     throws WeiboException {
   Utility.setAuthorization(new Oauth2AccessTokenHeader());
   WeiboParameters postParams = new WeiboParameters();
   postParams.add("username", usrname);
   postParams.add("password", password);
   postParams.add("client_id", app_key);
   postParams.add("client_secret", app_secret);
   postParams.add("grant_type", "password");
   String rlt = Utility.openUrl(context, Weibo.URL_OAUTH2_ACCESS_TOKEN, "POST", postParams, null);
   Oauth2AccessToken accessToken = new Oauth2AccessToken(rlt);
   this.mAccessToken = accessToken;
   return accessToken;
 }
Ejemplo n.º 5
0
  private void authorize(
      Activity activity,
      String[] permissions,
      int activityCode,
      final WeiboDialogListener listener) {
    Utility.setAuthorization(new Oauth2AccessTokenHeader());

    boolean singleSignOnStarted = false;
    mAuthDialogListener = listener;

    // Prefer single sign-on, where available.
    if (activityCode >= 0) {
      singleSignOnStarted = startSingleSignOn(activity, APP_KEY, permissions, activityCode);
    }
    // Otherwise fall back to traditional dialog.
    if (!singleSignOnStarted) {
      startDialogAuth(activity, permissions);
    }
  }