Skip to content

Instantly share code, notes, and snippets.

Created December 7, 2013 04:18
Show Gist options
  • Save rhenium/7837212 to your computer and use it in GitHub Desktop.
Save rhenium/7837212 to your computer and use it in GitHub Desktop.
Twitter for Android を使って OAuth 認証できるっぽいので
package jp.rhe.test.twitterauth;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class MainActivity extends Activity {
private final int REQUEST_CODE = 280414022;
private static final ComponentName AUTH_ACTIVITY = new ComponentName("", "");
protected void onCreate(Bundle savedInstanceState) {
findViewById( OnClickListener() {
public void onClick(View arg0) {
Intent localIntent = new Intent().setComponent(AUTH_ACTIVITY);
localIntent.putExtra("ck", "IQKbtAYlXLripLGPWd0HUA");
localIntent.putExtra("cs", "GgDYlkSvaPxGxC4X8liwpUoqKwwr3lCADbz8A7ADU");
startActivityForResult(localIntent, REQUEST_CODE);
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(, menu);
return true;
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE && data != null) {
// requestCode == REQUEST_CODE && data == null は Cancel?
Bundle extras = data.getExtras();
((TextView) findViewById("Access Token: " + extras.getString("tk"));
((TextView) findViewById("Access Token Secret: " + extras.getString("ts"));
((TextView) findViewById("Screen Name: " + extras.getString("screen_name"));
((TextView) findViewById("User ID: " + extras.getLong("user_id"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment