How to integrate twitter into android to enter twitter after removing it from the fabric?

I am trying to integrate twitter login. Twitter login button is not available. I read somewhere that I need to add this line before setting the content so that it works:

TwitterAuthConfig authConfig =  new TwitterAuthConfig(
                getString(R.string.twitter_consumer_key),
                getString(R.string.twitter_consumer_secret));

        Fabric.with(this, new Twitter(authConfig));//here,i am having problem

        setContentView(R.layout.activity_cover);

But Android Studio does not recognize Fabric. She has a red color. This is the code:

Fabric.with (this is the new Twitter (authConfig));

In addition, there is a red signature under Twitter, and I have the following error:

'Twitter (com.twitter.sdk.android.core.TwitterConfig)' has private access to 'com.twitter.sdk.android.core.Twitter'

In addition, I tried the twin Android studio plugin, but there is no option to enter twitter:

fabric plug

+1
3

Fabric.with(this, new Twitter(authConfig));

:

        TwitterConfig.Builder builder=new TwitterConfig.Builder(this);
        builder.twitterAuthConfig(authConfig);
        Twitter.initialize(builder.build());

, gradle ( ):

compile 'com.twitter.sdk.android:twitter:3.0.0'

+1

. Google Fabric Twitter, Twitter Kit Fabric. . , , .

1) init.

2) build.gradle :

dependencies {
  // Include all the Twitter APIs
  compile 'com.twitter.sdk.android:twitter:3.0.0'
  // (Optional) Monetize using mopub
  compile 'com.twitter.sdk.android:twitter-mopub:3.0.0'
}

3) , jcenter :

repositories {
  jcenter()
}

4) Twitter onCreate():

public class CustomApplication {
  public void onCreate() {
    Twitter.initialize(this);
  }
}

5) API :

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

build.gradle

dependencies {


 compile 'com.twitter.sdk.android:twitter-core:3.1.0'
  compile 'com.twitter.sdk.android:tweet-ui:3.1.0'
  compile 'com.twitter.sdk.android:tweet-composer:3.1.0'
  compile 'com.twitter.sdk.android:twitter-mopub:3.1.0'
}

repositories {
  jcenter()
}

Initialize Twitter kit in oncreate () activity

Twitter.initialize(this);

Add your API key and secret to your application resources.

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

Add Twitter button to xml

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

Initialize the Twitter button and get TwitterSession .. if successful, get user information

loginButton = (TwitterLoginButton) view.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
        Log.e("result", "result " + result);
        TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient();
        AccountService accountService = twitterApiClient.getAccountService();
        Call<User> call = accountService.verifyCredentials(true, true, true);
        call.enqueue(new Callback<com.twitter.sdk.android.core.models.User>() {
            @Override
            public void success(Result<com.twitter.sdk.android.core.models.User> result) {
                //here we go User details
                Log.e("result", "result user " + result);
                String imageUrl = result.data.profileImageUrl;
                String email = result.data.email;
                String userName = result.data.name;
                System.out.println(imageUrl);
                System.out.println(email);
                System.out.println(userName);




        }
        @Override
        public void failure(TwitterException exception) {
            exception.printStackTrace();
        }
    });
}
@Override
public void failure(TwitterException exception) {
    // Do something on failure
    exception.printStackTrace();
}
});

If your button is in a snippet, add the following code to the action

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    //verificationFragment is my fragment
    verificationFragment.onActivityResult(requestCode, resultCode, data);
}

Add the following code snippet

public 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);


}
0
source

Source: https://habr.com/ru/post/1678485/


All Articles