Android UmengShareSDK第三方登入

來源:互聯網
上載者:User

標籤:android   style   http   color   os   io   width   for   

Android UmengShareSDK 第三方登入- 今天就不廢話了,整合平台第三方登入。市面上整合平台有shareSDK 和 Ument兩種,shareSDK的ipa和服務好些,如果自己研究會很方便。其他功能錯不多,這騙文章將概述Ument的第三方登入。

  1. 首先你得到友盟上去建立帳戶和應用這是連結http://www.umeng.com/,擷取你應用的Appkey在manifest中配置。
  2. 下載Ument整合SDK,複製res和blis到你工程中或者添加依賴庫並配置mainfest。
  3. 在你的主程中定義UMSocialService。建議在application中
    public static final UMSocialService mController = UMServiceFactory .getUMSocialService("com.umeng.share", RequestType.SOCIAL);
  4. 在初始化init中添加監聽
  5. mController.getPlatformInfo(this, SHARE_MEDIA.SINA, new UMDataListener() { @Override public void onStart() { }

    @Override public void onComplete(int status, Map<String, Object> info) { // 相關平台的授權資訊都以K-V的形式封裝在info中 if (status == 200 && info != null) { StringBuilder sb = new StringBuilder(); Set<String> keys = info.keySet(); token = (String) info.get("access_token"); for (String kStr : keys) { sb.append(kStr + "=" + info.get(kStr).toString() + "\r\n"); } Toast.makeText(MainActivity.this, token, 0).show(); GeneralUtil.DebuggingLog(TAG, sb.toString()); } else GeneralUtil.DebuggingLog(TAG, "失敗"); } });

    }`

  6. 第三方登入的資訊會在回調後的info中以索引值對的形式存在。通過setkey可以拿到鍵集合。

  7. 接下來就可以儲存最重要的token了,完事在你的授權監聽中添加 mController.doOauthVerify(this, SHAREMEDIA.SINA, new UMAuthListener() { @Override public void onStart(SHAREMEDIA arg0) { }

    @Override public void onError(SocializeException arg0, SHARE_MEDIA arg1) { } @Override public void onComplete(Bundle arg0, SHARE_MEDIA arg1) { Toast.makeText(MainActivity.this, token, 0).show(); } @Override public void onCancel(SHARE_MEDIA arg0) { } });`
  8. onComplete方法就是成功回調,其他可以參考api.

  • Ument第三方登入講解到此為止,ument的api並沒有很詳細,在搜尋引擎並未能發現比較直接好的例子。如果參照dome可能會走些彎路。希望這個簡單直接的教程能夠給後輩們一些個啟發。

this is not nonsense, integration platform of third party logging. The market integration platform with shareSDK and Ument two, shareSDK IPA and service better, if your research will be very convenient. The other function is not wrong, this article will provide an overview of Ument third logon.

  1. first you get the alliance to create the account and the application of this is the link [http://www.umeng.com/] (http://www.umeng.com/), get your application in the manifest configuration Appkey.
  2. download Ument integrated SDK, copy the res and BLIS to your project or add library dependencies and configuration of mainfest.
  3. in the LORD your process definition UMSocialService. Suggestions in applicationpublic static final UMSocialService mController = UMServiceFactory .getUMSocialService (&quot; com.umeng.share&quot, RequestType.SOCIAL;);
  4. in the initialization init add monitor
  5. mController.getPlatformInfo (this, SHAREMEDIA.SINA, New UMDataListener () { @Override Public (void onStart) { } @Override Public void onComplete (int status, Map<String, Object> info) { / / relevant platform authorization information in the form of K-V package in info If (status = = 200 & & Info! = null) { StringBuilder sb = new (StringBuilder); Set keys = info.keySet (); Token = (String) info.get ("accesstoken"); For (String kStr: Keys) { Sb.append (kStr + "=" Info.get (kStr) + (.ToString) + "\r\n"); } Toast.makeText (MainActivity.this, token,.Show (0)); GeneralUtil.DebuggingLog (TAG, sb.toString) (); } else GeneralUtil.DebuggingLog (TAG, "failure"); } }); }`
  6. third party login information will exist in the form of key / value in the callback after info. Through the setkey can get the key set.
  7. then you can save the most important token, and add mController.doOauthVerify in authorization monitoring your in ( this, SHAREMEDIA.SINA, New UMAuthListener () { @Override Public void onStart (SHAREMEDIA arg0) { } @Override Public void onError (SocializeException arg0, SHARE_MEDIA arg1) { } @Override Public void onComplete (Bundle arg0, SHAREMEDIA arg1) { Toast.makeText (MainActivity.this, token,.Show (0)); } @Override Public void onCancel (SHAREMEDIA arg0) { } ‘);}
  8. onComplete is a success callback, the other can refer to api.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.