当前位置: 代码迷 >> Android >> android应用关于新浪微博授权登陆解决方案
  详细解决方案

android应用关于新浪微博授权登陆解决方案

热度:101   发布时间:2016-05-01 21:24:34.0
android应用关于新浪微博授权登陆
下面的代码是在新浪微博的weibo4android中拷过来的,请问为什么requestToken=weibo.getOAuthRequestToken("Photo://OAuthActivity");网页授权后无法进入到OAuthActivity页面呢?
大神们帮帮忙啊!!!!!!!!


weibo类
package com.demo.android.photo;

import weibo4android.Weibo;
import weibo4android.WeiboException;
import weibo4android.http.RequestToken;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

public class weibo extends Activity {
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.weibo);
  System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
  System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);
  Weibo weibo = OAuthConstant.getInstance().getWeibo();
RequestToken requestToken;
try {
requestToken =weibo.getOAuthRequestToken("Photo://OAuthActivity"); // 分别取第八点提到的scheme host ---host必须为在新浪成功后所需要调回的页面名称
Uri uri = Uri.parse(requestToken.getAuthenticationURL()+ "&from=xweibo"); // 即OAuthActivity的对应文件。 scheme建议为项目名称或是项目总的命名空间
OAuthConstant.getInstance().setRequestToken(requestToken);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
} catch (WeiboException e) {
e.printStackTrace();
}
//Intent intent=new Intent();
//intent.setClass(weibo.this, OAuthActivity.class);
  }
}

OAuthActivity类
package com.demo.android.photo;

import java.util.List;

import weibo4android.Paging;
import weibo4android.Status;
import weibo4android.Weibo;
import weibo4android.WeiboException;
import weibo4android.http.AccessToken;
import weibo4android.http.RequestToken;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class OAuthActivity extends Activity {

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.weibo1);
Uri uri=this.getIntent().getData();
try {
RequestToken requestToken= OAuthConstant.getInstance().getRequestToken();
AccessToken accessToken=requestToken.getAccessToken(uri.getQueryParameter("oauth_verifier"));
OAuthConstant.getInstance().setAccessToken(accessToken);
TextView textView = (TextView) findViewById(R.id.TextView01);
textView.setText("得到AccessToken的key和Secret,可以使用这两个参数进行授权登录了.\n Access token:\n"+accessToken.getToken()+"\n Access token secret:\n"+accessToken.getTokenSecret());
} catch (WeiboException e) {
e.printStackTrace();
}
Button button= (Button) findViewById(R.id.Button01);

//
}
}


------解决方案--------------------
先看看Uri对不对,然后查查scheme="weibo4android"是不是有大写的或者写的不对.
  相关解决方案