Пример #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;
 }
Пример #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;
 }
Пример #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;
 }
Пример #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;
 }
Пример #5
0
 /**
  * Requst sina weibo open api by get or post
  *
  * @param url Openapi request URL.
  * @param params http get or post parameters . e.g. gettimeling?max=max_id&min=min_id max and
  *     max_id is a pair of key and value for params, also the min and min_id
  * @param httpMethod http verb: e.g. "GET", "POST", "DELETE"
  * @throws IOException
  * @throws MalformedURLException
  * @throws WeiboException
  */
 public String request(
     Context context, String url, WeiboParameters params, String httpMethod, Token token)
     throws WeiboException {
   String rlt = Utility.openUrl(context, url, httpMethod, params, this.mAccessToken);
   return rlt;
 }