如果大家开发过Android版的新浪微博客户端可以通过如下接口直接在客户端返回oauth_verifier

以下是我加的方法,注意增加了userId和passwd参数,大小写userId的I是大写,该问题困扰了我1晚上。

l public String getAuthorizationVerifier(String uid,String pass) { l return httpClient.getAuthorizationURL() + "?oauth_token=" + getToken()+"&userId="+uid+"&passwd="+pass+"&oauth_callback=json"; l l } 但是在腾讯中没有该方法,只能弹出页面,之后就跳转到了另一个url,而oauth_verifier在url中,不能通过代码直接获取,其实在Android中式可以解决的,如下图: 因为,Android中不同的URl可以由我们自定义的Activity组件来处理,而不一定是Webkit,实现方法如下: 编写入口Acitivity实现如下代码: package com.qqtest;
import com.qq.weibo.OAuth;
import com.sdhjob.util.ConfigUtil; import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.webkit.DownloadListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast; public class MainTest extends Activity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String key = ConfigUtil.getValue("qq.weibo.appKey");
String secret = ConfigUtil.getValue("qq.weibo.appSecret");
OAuth oAuth = new OAuth(key,secret);
WebView w=(WebView)this.findViewById(R.id.ok);
// 运行完后注释掉这段 放开 32行到37行的代码
String oauthToken = oAuth.getOauthToken();
Log.d("qq","oauthToken="+oauthToken);
if( this.getIntent()!=null&&this.getIntent().getData()!=null)
{
Uri uri = this.getIntent().getData();
//验证码
String oauth_verifier = uri.getQueryParameter("oauth_verifier");
Toast.makeText(this,"验证码"+oauth_verifier, 1000).show();
}else

if(oauthToken != null){
final String url=" https://open.t.qq.com/cgi-bin/authorize?"+oauthToken;
Intent it=new Intent(Intent.ACTION_VIEW,Uri.parse(url));
this.startActivity(it);
}
}
} 红色部分是怎么实现的呢,看androidmanifest .xml: <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=" http://schemas.android.com/apk/res/android"
package="com.qqtest"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainTest"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>

<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="qqweibook" />
<data android:host="qqweibo.sdhjob" />

</intent-filter>
</activity> </application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest> /////////////////////////////////////////// <data android:host是在请求腾讯的api时候加入的参数 oauth_callback = "qqweibook://qqweibo.sdhjob"; // —— 用户授权后的返回地址 /////////////////////////////////////////////////////////////////// 至于怎么使用腾讯API不说了,你懂的............................................................................ 源代码下载地址:
http://download.csdn.net/source/3205035

更多相关文章

  1. Android(安卓)Dialog设置TYPE_SYSTEM_ALERT 小米,魅族手机不能显
  2. Android下载repo文件报错
  3. 纯css3无js实现的Android(安卓)Logo(有简单动画)
  4. Android配置文件(.properties文件)的使用
  5. Android(安卓)WebRTC 音视频开发总结(二)
  6. R.bool.use_32bit
  7. 格局中@null的代码实现方式
  8. Android培训班(57)Dalvik虚拟机运行ZygoteInit类
  9. 转:android下拉列表框 spinner

随机推荐

  1. 0基础学习Python该如何入门?Python学习方
  2. [翻译]微服务设计模式 - 8. 服务发现 -
  3. 如何在苹果Mac上的“邮件”中导入或导出
  4. [翻译]微服务设计模式 - 7. 服务发现 -
  5. nginx负载均衡简单设置
  6. Linux下典型IO模型 +select多路转接模型(
  7. JS数组性能小则|你以为的快不是真的快
  8. 曝苹果新款iPad Pro最早4月推出:配备雷电
  9. ProBuilder快速原型开发技术 ---进阶功能
  10. nginx反向代理443端口