
Custom Twitter login button SDK (Fabric kit)
This article is intended for those who have already figured out how to install and configure Twitter Login SDK ( Fabric kit ), but are stuck on the question of how to implement custom ui for the login button. An introductory article on Fabric can be found here .
“Finally, I will get rid of this bulky code,” I thought, cutting out twitter4j and anticipating how neat authorization classes would be thanks to the Twitter SDK. It was Saturday morning. According to my calculations, this should have taken no more than an hour. In the evening, I cursed that morning fool who decided to sacrifice a whole day off for a little refactoring.
What happened? First of all, do not believe that the Fabric plugin will do everything for you. Quite the contrary - you still cry with him. So those who solves login advise parallel glances here here .
With the TwitterLoginButton widget that sdk provides, everything is clear, but what about those who are not comfortable with the standard design? Long hours of googling didn’t give anything. The complete absence of api references, java doc or source code also did not simplify the task.
In the end, I found a crutch like this:
And so that all this works (oh horror!):
After a couple of days, I didn’t give a damn, I found the strength to find a normal solution. Everything turned out to be quite simple:
If you have more recent information on sdk documentation, please write - I will be happy to add it to the article.
Source code on Github: github.com/Defuera/Social-network-login
“Finally, I will get rid of this bulky code,” I thought, cutting out twitter4j and anticipating how neat authorization classes would be thanks to the Twitter SDK. It was Saturday morning. According to my calculations, this should have taken no more than an hour. In the evening, I cursed that morning fool who decided to sacrifice a whole day off for a little refactoring.
What happened? First of all, do not believe that the Fabric plugin will do everything for you. Quite the contrary - you still cry with him. So those who solves login advise parallel glances here here .
With the TwitterLoginButton widget that sdk provides, everything is clear, but what about those who are not comfortable with the standard design? Long hours of googling didn’t give anything. The complete absence of api references, java doc or source code also did not simplify the task.
In the end, I found a crutch like this:
private void loginToTwitter() {
TwitterCore.getInstance().logIn(this, new Callback() {
@Override
public void success(Result twitterSessionResult) {
Log.i(LOG_TAG, "success");
}
@Override
public void failure(TwitterException e) {
Log.i(LOG_TAG, "failure");
}
});
}
And so that all this works (oh horror!):
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
(new TwitterLoginButton(this)).onActivityResult(requestCode, resultCode, data);
}
After a couple of days, I didn’t give a damn, I found the strength to find a normal solution. Everything turned out to be quite simple:
private TwitterAuthClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
Fabric.with(this, new Twitter(authConfig));
Button customLoginButton = (Button) findViewById(R.id.custom_twitter_login);
customLoginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
client = new TwitterAuthClient();
client.authorize(LoginActivity.this, new Callback() {
@Override
public void success(Result twitterSessionResult) {
Toast.makeText(LoginActivity.this, "success", Toast.LENGTH_SHORT).show();
}
@Override
public void failure(TwitterException e) {
Toast.makeText(LoginActivity.this, "failure", Toast.LENGTH_SHORT).show();
}
});
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
client.onActivityResult(requestCode, resultCode, data);
}
If you have more recent information on sdk documentation, please write - I will be happy to add it to the article.
Source code on Github: github.com/Defuera/Social-network-login