十五、Android學習筆記_授權過程

來源:互聯網
上載者:User

標籤:android   style   class   blog   code   java   

1、需要申請App Key和App Secret。不同的開發平台有不同的接入方式,可以參考文檔,然後將這兩個值放進去。2、通過OAuth類實現認證,它會自動跳轉到認證介面,進行授權,成功之後需要處理回調介面。3、在第二步調用回調介面時,它會返回使用者的基本資料,比如使用者id。此時需要將使用者id資訊儲存起來,為後面登入做準備。回調介面的寫法就為myapp://AuthorizeActivity,其中scheme全部為小寫字母。    <activity android:name="com.weibo.view.AuthActivity" android:launchMode="singleTask">            <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="myapp" android:host="AuthActivity" />        </intent-filter>        </activity>4、在進行登入時,先到資料庫查詢是否存在使用者id,token,access token等資訊,如果有表示已經授權,否則就跳轉到授權介面,進行授權。5、授權成功後,擷取使用者token等資訊。如果此時要載入使用者資訊(比如使用者好友),根據API載入好友的url和配置參數,就可以擷取伺服器返回來的資料。如下response就包含了使用者好友的資訊。        OAuth auth=new OAuth();        String url = "http://api.t.sina.com.cn/statuses/friends_timeline.json";        List<BasicNameValuePair> params=new ArrayList<BasicNameValuePair>();        params.add(new BasicNameValuePair("source", auth.consumerKey));         HttpResponse response = auth.SignRequest(user.getToken(), user.getTokenSecret(), url, params);          

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.