I have many examples for O_Auth, but no one is working properly, and I think that the only thing that is the return URL in each example, I get error 401, for example, the consumer key or signature does not match. I have already seen so many examples on 401, the only thing that concerns me is my callback.
Android app cannot connect to twitter . Getting 401 when requesting an access token with a pointer inside android with-signpost-in-android Android Dev - the callback URL does not work ... (0_o)
I have already seen all these examples and much more.
But still, I don’t understand if during the application form I use http://www.meomyo.com at the return URL, then I should use it in my coding as android: scheme = "?" android: "?" host = I use other callback examples
private static final Uri CALLBACK_URI = Uri.parse("twitterapp://connect");
I have a key for the user as well as a secret key, but in the case of url callback I got stuck on it. If someone wants, I can provide my consumer, as well as a secret key.
public class OAuth extends Activity {
private static final String APP = "OAUTH";
private Twitter twitter;
private OAuthProvider provider;
private CommonsHttpOAuthConsumer consumer;
private String CONSUMER_KEY = "Xh3o8Gh1JQnklkUnTvvA";
private String CONSUMER_SECRET = "SCLy6yoUSth53goAsYYkoqR4ZuBoaInyJXsm5PQR11I";
private String CALLBACK_URL = "merabharatmahan://piyush";
private TextView tweetTextView;
private Button buttonLogin;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tweetTextView = (TextView)findViewById(R.id.tweet);
buttonLogin = (Button)findViewById(R.id.ButtonLogin);
buttonLogin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
askOAuth();
}
});
}
private void askOAuth() {
try {
consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
provider = new DefaultOAuthProvider("http://twitter.com/oauth/request_token",
"http://twitter.com/oauth/access_token",
"http://twitter.com/oauth/authorize");
String authUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL);
Toast.makeText(this, "Please authorize this app!", Toast.LENGTH_LONG).show();
this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
} catch (Exception e) {
Log.e(APP, e.getMessage());
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Uri uri = intent.getData();
if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
String verifier = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER);
try {
provider.retrieveAccessToken(consumer, verifier);
AccessToken a = new AccessToken(consumer.getToken(), consumer.getTokenSecret());
twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
twitter.setOAuthAccessToken(a);
Date d = new Date(System.currentTimeMillis());
String tweet = "#OAuth working! " + d.toLocaleString();
twitter.updateStatus(tweet);
tweetTextView.setText(tweet);
Toast.makeText(this, tweet, Toast.LENGTH_LONG).show();
buttonLogin.setVisibility(Button.GONE);
} catch (Exception e) {
Log.e(APP, e.getMessage());
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
}
manifest code
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".OAuth"
android:label="@string/app_name"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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="merabharatmahan" android:host="piyush" />
</intent-filter>
</activity>
</application
Now I get a message with the service provider crashing: the received authentication is zero. This is the simplest example that I set here.