600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > android授权新浪微博 服务端 android应用关于新浪微博授权登陆解决方案

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

时间:2018-08-22 01:52:19

相关推荐

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

当前位置:我的异常网» Android»android应用关于新浪微博授权登陆解决方案

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

网友分享于:-05-02浏览:360次

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 .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 .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"是不是有大写的或者写的不对.

文章评论

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。