Twitter I held my first developer conference in four years . And this one is called “Flight” The general assembly of , It's also its annual routine in the future .

The theme of this conference is all about developers . The focus of the conference is a person named Fabric The new SDK, It includes three developer kits : oriented Twitter Of itself Twitter Kit、 oriented Twitter Advertising network MoPub, And based on Twitter 2013 Mobile app crash analysis tool acquired in Crashlytics Of Crashlytics Kit.

I'll stick it first twitter Log in to the official website of :https://dev.twitter.com/twitterkit/android/log-in-with-twitter, But it's all in English , Of course , We need to climb a wall to get online .

First of all, we need to register twitter Developer account , And create applications ,https://apps.twitter.com.

Click on the top right corner to create the app :

And then we'll go to the picture below :

We need to fill in the name of the app , And the description of the application , as for website, The following explanation probably means :
The publicly accessible home page of your application , Users can download , Use or find out more about your app . It's totally limited URL For source application creation tweets, And it will be displayed in the user oriented authorization screen .
( If you haven't URL, Just place a place holder here , But remember to change it later .)

After the application is created , We can go to the app to see the relevant settings , Click on Keys and Access Tokens, You can see Consumer Key (API Key) and Consumer Secret (API Secret), These two need to be used

Okay , That's all for creating apps , Next, how to integrate into our project :

( One ) First we need to integrate twitter dependent sdk, It's written a lot on the official website , If you only need the login function , So just

stay build.gradle(app) It says

dependencies {
compile 'com.twitter.sdk.android:twitter-core:3.1.1'
}

stay build.gradle(project) Of  repositories It says

repositories {
jcenter()
}

( Two ) Add in our resource file API KEY, This API KEY stay twitter We can see that , These are the two we mentioned above

<resources>
<string android:name="com.twitter.sdk.android.CONSUMER_KEY">XXXXXXXXXXX</string>
<string android:name="com.twitter.sdk.android.CONSUMER_SECRET">XXXXXXXXXXX</string>
</resources>

( 3、 ... and ) Create a custom Application, stay onCreate() Initialization in method

 Twitter.initialize(this);
TwitterConfig config = new TwitterConfig.Builder(this)
.logger(new DefaultLogger(Log.DEBUG))
.twitterAuthConfig(new TwitterAuthConfig("CONSUMER_KEY", "CONSUMER_SECRET"))
.debug(true)
.build();
Twitter.initialize(config);

( Four ) We can use twitter Provide a good login button , Of course, it can also be customized , Next I'll talk about .

<com.twitter.sdk.android.core.identity.TwitterLoginButton
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

( 5、 ... and ) In the code :

loginButton = (TwitterLoginButton) findViewById(R.id.login_button);
loginButton.setCallback(new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
// Do something with result, which provides a TwitterSession for making API calls
 result It contains user information , We can take it out token,tokenSecret
( If we had our own back-end server , Send these two to our own back office , Backstage to verify )
 TwitterAuthToken authToken = result.data.getAuthToken();
 String token = authToken.token;
 String appId = getResources().getString(R.string.twitter_app_id);
String tokenSecret = authToken.secret;
 }
 @Override public void failure(TwitterException exception) { // Do something on failure } });
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); // Pass the activity result to the login button.
loginButton.onActivityResult(requestCode, resultCode, data);
}
 

  If the login button is in fragment In the words of , that onActivityResult You should use the following code :

should

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); // Pass the activity result to the fragment, which will then pass the result to the login
// button.
Fragment fragment = getFragmentManager().findFragmentById(R.id.your_fragment_id);
if (fragment != null) {
fragment.onActivityResult(requestCode, resultCode, data);
}
}

The rest can refer to the official website

The next one is the custom login button , In fact, there is a clever plan , Please see the interface code below :

<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/facebook"
android:layout_marginTop="@dimen/login_button_margin_bottom"
android:layout_centerHorizontal="true"> <com.twitter.sdk.android.core.identity.TwitterLoginButton
android:id="@+id/login_button"
android:layout_width="@dimen/button_width"
android:layout_height="@dimen/button_height"
android:layout_marginTop="@dimen/button_margin_bottom"
android:visibility="gone"/> <ImageView
android:id="@+id/login_image"
android:layout_width="@dimen/button_width"
android:layout_height="@dimen/button_height"
android:src="@drawable/twitter" />
</FrameLayout>

And then in the code :

@Override
public void onClick(View view) {
switch (view.getId()){case R.id.login_image:
LoginButton.performClick();
break;
default:
break;
}
}

namely , When we click our custom button , Give Way twitter The login button performs the click operation .

First come here. , I'll add it later .

Reprint please indicate the source :http://www.cnblogs.com/tangZH/p/8206569.html

android Integrate twitter Login for more related articles

  1. Android Facebook and Twitter Log in and share the full version

    Recently, the company's software needs to be changed to the international version , need Facebook and Twitter Login and share . I use it first Umeng The third-party social sharing of realizes this function , But when I thought about it, the problem came , After verification .Umeng There are servers only in China and the United States , That too ...

  2. android Application Integration facebook Sign in

      I used to do domestic application development , I haven't used the third party login from abroad , Like Google login .facebok Sign in , Recently participated in an overseas payment related project , Did some research on Google login and facebook Sign in , In fact, after investigation, I think it's very simple , especially ...

  3. android Application Integration google Sign in

         Integrate google There are three requirements before logging in , Only with the following two requirements can we integrate google Sign in :         1,android  Run version 4.0 And update         2,android  set up ...

  4. android Integrate QQ interconnection ( Sign in , Share )

    Reference resources :http://blog.csdn.net/syz8742874/article/details/39271117 http://blog.csdn.net/woblog/article/deta ...

  5. Android UmengShareSDK Third party login

    Android UmengShareSDK Third party login - No nonsense today , Integration platform third party login . The integrated platforms on the market are shareSDK and Ument Two kinds of ,shareSDK Of ipa And the service is better , If you study by yourself, it will be very ...

  6. A user portrait product ( Like )Android Integrated practice

    Our team has always been a loyal user of push , Recently, a new product has been launched “ Like · User portrait ”, It just fits our business needs very well , So we tried it . Generally speaking, the effect is not bad , This article will introduce how to quickly integrate an image from scratch An ...

  7. Android ShareSDKQQ Third party login so easy?

    Yesterday, a group friend in the group saw the one I did before qq How to do the third party login , So I thought about it , Or decided to write a blog to record . It's not hard, actually , In fact, I wrote before FaceBook I don't know what to do with the third party login Android Integrate Fac ...

  8. [ Roof placement ] Android ShareSDKQQ Third party login so easy?

    Yesterday, a group friend in the group saw the one I did before qq How to do the third party login , So I thought about it , Or decided to write a blog to record , It's not hard , In fact, I wrote before FaceBook I don't know what to do with the third party login Android Integrate FaceB ...

  9. Android Wechat third party login ( Personal notes )

    I'm writing wechat login today , It took half a day to get it done . Then write down your notes , Hope to help more people ... Welcome your advice . Wechat authorized login , The official statement is not very clear . So it leads to a part of the pit . Application signature of wechat registration application platform , download   Wechat signature generator ...

Random recommendation

  1. C# Several problems encountered in the work

    C#  Several problems encountered in the work 1. take VS2010 The default font for the code editor in “ NSimSun ” Change it to “ Microsoft YaHei ” after , Comments to code , It's hard to align , Especially with SandCastle Help File Builder Generate help documents ...

  2. 【 primary 】linux rm Detailed explanation of the command and the actual use of it

    rm: The delete command Preface : windows We are not unfamiliar with the delete command in ,linux The delete command in and windows There's one thing that's common to all of us , That's the danger , The first two linux mkdir Detailed explanation of the command and the actual use of it [ primary ] We just ...

  3. DataGridView Custom column sorting for

    1, Set the properties of the columns to be sorted this.colUserName.SortMode = DataGridViewColumnSortMode.Programmatic; 2, Add column Events // Click on ...

  4. mysql note ( What I wrote in front is not standard. There are some places )

    day15-MySQL database 1 Database concept ( understand ) 1.1 What is a database A database is a warehouse for storing and managing data ! The priority of storing data in a database : l  It can store a lot of data : l  Convenient retrieval : l  Keep a part of the data ...

  5. Android Multithreading research (4)—— Start with an interview question

    There's an interview question like this : Turn on a child thread to run at the same time as the main thread , Child thread output 10 Next, the main thread outputs 100 Time , repeat 50 Time . First look at the following code : package com.maso.test; /** * * @auth ...

  6. reflection java web The development of

    Originally, websites are all static HTML Of , But soon we won't be satisfied with that . Dynamic web pages came into being . At first it was Servlet. The code is similar to the following . Mainly Java Code , And then use out Bit by bit output HTML Code . Of course, the code is ugly ...

  7. Ibatis course

    Ibatis course | Font size     from :http://blog.csdn.net/lhminjava/article/details/1871136 ibatis Development of guidelines ibatis Quick S ...

  8. linux Programming basics summary

    linux Programming basics summary http://newzol.cn/forum.php?mod=viewthread&tid=67&fromuid=3( Source : newzol) 1. The Conduit http ...

  9. PHP Achieve form submission, send mail

    It only takes three files : Be careful : File self naming needs to modify form submission url, Contains the class file name : HTML Form file : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...

  10. Oracle 12C perform root.sh CLSRSC-119 CRS-8503 CLSRSC-366

    1. Environmental Science OS:SUSE Linux Enterprise 12 SP3 X86_64 (Kernel: 4.4.162-94.69.2) DB:12.2.0.1 Two node RAC Reference documents : stay SLES ...