日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

2011年沈大海講師Android的騰訊微博客戶端源代

系統 2356 0

如果大家開發過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不說了,你懂的............................................................................

2011年沈大海講師Android的騰訊微博客戶端源代碼,實現oauth_verifier自動提取!


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!??!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 永吉县| 新宾| 灵山县| 南澳县| 延寿县| 岳池县| 阿鲁科尔沁旗| 基隆市| 临猗县| 满洲里市| 五家渠市| 三门峡市| 界首市| 且末县| 山东省| 绥化市| 五家渠市| 常州市| 富蕴县| 吉安县| 丰都县| 曲水县| 溧阳市| 齐齐哈尔市| 富蕴县| 谢通门县| 青浦区| 迁西县| 宝应县| 昭通市| 织金县| 呼图壁县| 桐梓县| 镇康县| 鄢陵县| 赣州市| 临朐县| 武川县| 景宁| 隆安县| 德清县|