[twitter-dev] Re: Problems with Twitter4J and OAuth on Android

2010-07-21 Thread Clay Graham
Dooh. I thought I changed that.

Thanks. Luckily its a test pair.

Clay

On Jul 21, 12:13 pm, Taylor Singletary taylorsinglet...@twitter.com
wrote:
 Hi Clay,

 Just noticed that you have an API secret in this code sample you've
 provided -- you'll want to go to your application record and
 regenerate a new key/secret pair.

 As for the code itself -- I see you setting your consumer key and
 secret as constants near the top, but then in askOAuth you're using
 different values -- is this just a result of a bad paste?

 Taylor

 On Tue, Jul 20, 2010 at 11:18 PM, Clay Graham claytan...@sightlyinc.com 
 wrote:
  Cant figure out if this is a problem with Twitter4J or the Twitter
  API. I am trying to create an OAuth callback activity, started by a
  RequestToken, but the Request Token request is failing. DOES ANYONE
  KNOW IF GOOGLE HAS MADE THE TWITTER CLIENT AVAILABLE BY OPEN SOURCE
  YET?

  Twitter4J 2.1.2
  Android Froyo 2.2

  package com.sightlyinc.oauth.android;

  import java.util.Date;

  import twitter4j.Twitter;
  import twitter4j.TwitterFactory;
  import twitter4j.http.AccessToken;
  import twitter4j.http.RequestToken;
  import android.app.Activity;
  import android.content.Intent;
  import android.content.SharedPreferences;
  import android.content.SharedPreferences.Editor;
  import android.net.Uri;
  import android.os.Bundle;
  import android.preference.PreferenceManager;
  import android.util.Log;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;

  public class SightlyOauthActivity extends Activity {

     private static final String TAG =
  SightlyOauthActivity.class.getName();

     private Twitter twitter;
     private RequestToken requestToken;
     private SharedPreferences mSharedPreferences;

     private String CONSUMER_KEY =           yfKRsmTgi8UT8eHoV5Khrw;
     private String CALLBACK_URL =           sightlyoauth://oauth;

     private EditText tweetTextView;
     private Button buttonLogin;

         /** Called when the activity is first created. */
        �...@override
         public void onCreate(Bundle savedInstanceState) {
                 super.onCreate(savedInstanceState);
                 setContentView(R.layout.main);

                 mSharedPreferences =
                         PreferenceManager.getDefaultSharedPreferences(
                                         getApplicationContext());

                 tweetTextView =
  (EditText)findViewById(R.id.TweetView);
         buttonLogin = (Button)findViewById(R.id.ButtonLogon);
         buttonLogin.setOnClickListener(new OnClickListener() {
                 public void onClick(View v) {
                         askOAuth();
                 }
         });

         }

         /**
          * Open the browser and asks the user to authorize the app.
  Afterwards, we
          * redirect the user back here!
          */
         private void askOAuth() {
                 try {

                         //setup properties, https was attempted and I
  was advised to
                         //use HTTPS instead.

  System.setProperty(twitter4j.http.useSSL,false);

  System.setProperty(twitter4j.oauth.consumerKey,MYKEY);

  System.setProperty(twitter4j.oauth.consumerSecret,MYSECRET);

  System.setProperty(twitter4j.oauth.requestTokenURL,http://
  api.twitter.com/oauth/request_token);

  System.setProperty(twitter4j.oauth.accessTokenURL,http://
  api.twitter.com/oauth/access_token);

  System.setProperty(twitter4j.oauth.authorizationURL,http://
  api.twitter.com/oauth/authorize);

                         //get the instance
                         Twitter twitter =
                                 new TwitterFactory().getInstance();

                         //THIS EXCEPTS WITH PERMISSION DENIED
                         requestToken =
  twitter.getOAuthRequestToken(CALLBACK_URL);

                         //set the request token info
                         Toast.makeText(this, Please authorize this
  app!,
                                         Toast.LENGTH_LONG).show();

                         this.startActivity(new
  Intent(Intent.ACTION_VIEW, Uri
                                         
  .parse(requestToken.getAuthenticationURL(;

                 } catch (Exception e) {
                         Log.e(TAG, e.getMessage(),e);
                         Toast.makeText(this, e.getMessage(),
  Toast.LENGTH_LONG).show();
                 }
         }

         /**
          * As soon as the user successfully authorized the app, we are
  notified
          * here. Now we need to get the verifier from the callback
  URL,
  retrieve
          * token and token_secret and feed them to twitter4j (as well
  as
  consumer
          * key and secret).
          */
        �...@override
         protected void onNewIntent(Intent intent) {

                 super.onNewIntent(intent);

                 Uri uri = 

[twitter-dev] Re: Problems with Twitter4J and OAuth on Android

2010-07-21 Thread Clay Graham
Taylor,

So the permission failure is on the request token. Not on the
callback, so even though my callback code is a little different it
shouldnt matter because it never gets to it.

Thanks again for catching that I posted my keys.

Clay


On Jul 21, 12:13 pm, Taylor Singletary taylorsinglet...@twitter.com
wrote:
 Hi Clay,

 Just noticed that you have an API secret in this code sample you've
 provided -- you'll want to go to your application record and
 regenerate a new key/secret pair.

 As for the code itself -- I see you setting your consumer key and
 secret as constants near the top, but then in askOAuth you're using
 different values -- is this just a result of a bad paste?

 Taylor

 On Tue, Jul 20, 2010 at 11:18 PM, Clay Graham claytan...@sightlyinc.com 
 wrote:
  Cant figure out if this is a problem with Twitter4J or the Twitter
  API. I am trying to create an OAuth callback activity, started by a
  RequestToken, but the Request Token request is failing. DOES ANYONE
  KNOW IF GOOGLE HAS MADE THE TWITTER CLIENT AVAILABLE BY OPEN SOURCE
  YET?

  Twitter4J 2.1.2
  Android Froyo 2.2

  package com.sightlyinc.oauth.android;

  import java.util.Date;

  import twitter4j.Twitter;
  import twitter4j.TwitterFactory;
  import twitter4j.http.AccessToken;
  import twitter4j.http.RequestToken;
  import android.app.Activity;
  import android.content.Intent;
  import android.content.SharedPreferences;
  import android.content.SharedPreferences.Editor;
  import android.net.Uri;
  import android.os.Bundle;
  import android.preference.PreferenceManager;
  import android.util.Log;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;

  public class SightlyOauthActivity extends Activity {

     private static final String TAG =
  SightlyOauthActivity.class.getName();

     private Twitter twitter;
     private RequestToken requestToken;
     private SharedPreferences mSharedPreferences;

     private String CONSUMER_KEY =           yfKRsmTgi8UT8eHoV5Khrw;
     private String CALLBACK_URL =           sightlyoauth://oauth;

     private EditText tweetTextView;
     private Button buttonLogin;

         /** Called when the activity is first created. */
        �...@override
         public void onCreate(Bundle savedInstanceState) {
                 super.onCreate(savedInstanceState);
                 setContentView(R.layout.main);

                 mSharedPreferences =
                         PreferenceManager.getDefaultSharedPreferences(
                                         getApplicationContext());

                 tweetTextView =
  (EditText)findViewById(R.id.TweetView);
         buttonLogin = (Button)findViewById(R.id.ButtonLogon);
         buttonLogin.setOnClickListener(new OnClickListener() {
                 public void onClick(View v) {
                         askOAuth();
                 }
         });

         }

         /**
          * Open the browser and asks the user to authorize the app.
  Afterwards, we
          * redirect the user back here!
          */
         private void askOAuth() {
                 try {

                         //setup properties, https was attempted and I
  was advised to
                         //use HTTPS instead.

  System.setProperty(twitter4j.http.useSSL,false);

  System.setProperty(twitter4j.oauth.consumerKey,MYKEY);

  System.setProperty(twitter4j.oauth.consumerSecret,MYSECRET);

  System.setProperty(twitter4j.oauth.requestTokenURL,http://
  api.twitter.com/oauth/request_token);

  System.setProperty(twitter4j.oauth.accessTokenURL,http://
  api.twitter.com/oauth/access_token);

  System.setProperty(twitter4j.oauth.authorizationURL,http://
  api.twitter.com/oauth/authorize);

                         //get the instance
                         Twitter twitter =
                                 new TwitterFactory().getInstance();

                         //THIS EXCEPTS WITH PERMISSION DENIED
                         requestToken =
  twitter.getOAuthRequestToken(CALLBACK_URL);

                         //set the request token info
                         Toast.makeText(this, Please authorize this
  app!,
                                         Toast.LENGTH_LONG).show();

                         this.startActivity(new
  Intent(Intent.ACTION_VIEW, Uri
                                         
  .parse(requestToken.getAuthenticationURL(;

                 } catch (Exception e) {
                         Log.e(TAG, e.getMessage(),e);
                         Toast.makeText(this, e.getMessage(),
  Toast.LENGTH_LONG).show();
                 }
         }

         /**
          * As soon as the user successfully authorized the app, we are
  notified
          * here. Now we need to get the verifier from the callback
  URL,
  retrieve
          * token and token_secret and feed them to twitter4j (as well
  as
  consumer
          * key and 

[twitter-dev] Re: Problems with Twitter4J and OAuth on Android

2010-07-21 Thread Clay Graham
Ok I know what the problem is!

The manifest was blocking connections to the internet because access
was not defined. AARRRG!

Here is the proper manifest. Hope this helps somebody

Sorry

?xml version=1.0 encoding=utf-8?
manifest xmlns:android=http://schemas.android.com/apk/res/android;
  package=com.sightlyinc.oauth.android
  android:versionCode=1
  android:versionName=1.0
application android:icon=@drawable/icon android:label=@string/
app_name
activity android:name=.SightlyOauthActivity
  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=sightlyoauth
android:host=oauth /
/intent-filter

/activity


/application

uses-permission
android:name=android.permission.ACCESS_COARSE_LOCATION/
uses-permission
android:name=android.permission.ACCESS_FINE_LOCATION/
uses-permission android:name=android.permission.INTERNET/

/manifest

On Jul 21, 12:13 pm, Taylor Singletary taylorsinglet...@twitter.com
wrote:
 Hi Clay,

 Just noticed that you have an API secret in this code sample you've
 provided -- you'll want to go to your application record and
 regenerate a new key/secret pair.

 As for the code itself -- I see you setting your consumer key and
 secret as constants near the top, but then in askOAuth you're using
 different values -- is this just a result of a bad paste?

 Taylor

 On Tue, Jul 20, 2010 at 11:18 PM, Clay Graham claytan...@sightlyinc.com 
 wrote:
  Cant figure out if this is a problem with Twitter4J or the Twitter
  API. I am trying to create an OAuth callback activity, started by a
  RequestToken, but the Request Token request is failing. DOES ANYONE
  KNOW IF GOOGLE HAS MADE THE TWITTER CLIENT AVAILABLE BY OPEN SOURCE
  YET?

  Twitter4J 2.1.2
  Android Froyo 2.2

  package com.sightlyinc.oauth.android;

  import java.util.Date;

  import twitter4j.Twitter;
  import twitter4j.TwitterFactory;
  import twitter4j.http.AccessToken;
  import twitter4j.http.RequestToken;
  import android.app.Activity;
  import android.content.Intent;
  import android.content.SharedPreferences;
  import android.content.SharedPreferences.Editor;
  import android.net.Uri;
  import android.os.Bundle;
  import android.preference.PreferenceManager;
  import android.util.Log;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;

  public class SightlyOauthActivity extends Activity {

     private static final String TAG =
  SightlyOauthActivity.class.getName();

     private Twitter twitter;
     private RequestToken requestToken;
     private SharedPreferences mSharedPreferences;

     private String CONSUMER_KEY =           yfKRsmTgi8UT8eHoV5Khrw;
     private String CALLBACK_URL =           sightlyoauth://oauth;

     private EditText tweetTextView;
     private Button buttonLogin;

         /** Called when the activity is first created. */
        �...@override
         public void onCreate(Bundle savedInstanceState) {
                 super.onCreate(savedInstanceState);
                 setContentView(R.layout.main);

                 mSharedPreferences =
                         PreferenceManager.getDefaultSharedPreferences(
                                         getApplicationContext());

                 tweetTextView =
  (EditText)findViewById(R.id.TweetView);
         buttonLogin = (Button)findViewById(R.id.ButtonLogon);
         buttonLogin.setOnClickListener(new OnClickListener() {
                 public void onClick(View v) {
                         askOAuth();
                 }
         });

         }

         /**
          * Open the browser and asks the user to authorize the app.
  Afterwards, we
          * redirect the user back here!
          */
         private void askOAuth() {
                 try {

                         //setup properties, https was attempted and I
  was advised to
                         //use HTTPS instead.

  System.setProperty(twitter4j.http.useSSL,false);

  System.setProperty(twitter4j.oauth.consumerKey,MYKEY);

  System.setProperty(twitter4j.oauth.consumerSecret,MYSECRET);

  System.setProperty(twitter4j.oauth.requestTokenURL,http://
  api.twitter.com/oauth/request_token);

  System.setProperty(twitter4j.oauth.accessTokenURL,http://
  api.twitter.com/oauth/access_token);

  System.setProperty(twitter4j.oauth.authorizationURL,http://
  

[twitter-dev] Re: Problems with Twitter4J and OAuth on Android

2010-07-21 Thread Bess
So does it works completely now with manifest.xml permission in place?
uses-permission
android:name=android.permission.ACCESS_COARSE_LOCATION/
uses-permission
android:name=android.permission.ACCESS_FINE_LOCATION/
uses-permission android:name=android.permission.INTERNET/

What OAuth lib did you use with Twitter4J?

On Jul 21, 6:08 pm, Clay Graham claytan...@sightlyinc.com wrote:
 Ok I know what the problem is!

 The manifest was blocking connections to the internet because access
 was not defined. AARRRG!

 Here is the proper manifest. Hope this helps somebody

 Sorry

 ?xml version=1.0 encoding=utf-8?
 manifest xmlns:android=http://schemas.android.com/apk/res/android;
       package=com.sightlyinc.oauth.android
       android:versionCode=1
       android:versionName=1.0
     application android:icon=@drawable/icon android:label=@string/
 app_name
         activity android:name=.SightlyOauthActivity
                   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=sightlyoauth
 android:host=oauth /
             /intent-filter

         /activity

     /application

         uses-permission
 android:name=android.permission.ACCESS_COARSE_LOCATION/
         uses-permission
 android:name=android.permission.ACCESS_FINE_LOCATION/
         uses-permission android:name=android.permission.INTERNET/

 /manifest

 On Jul 21, 12:13 pm, Taylor Singletary taylorsinglet...@twitter.com
 wrote:

  Hi Clay,

  Just noticed that you have an API secret in this code sample you've
  provided -- you'll want to go to your application record and
  regenerate a new key/secret pair.

  As for the code itself -- I see you setting your consumer key and
  secret as constants near the top, but then in askOAuth you're using
  different values -- is this just a result of a bad paste?

  Taylor

  On Tue, Jul 20, 2010 at 11:18 PM, Clay Graham claytan...@sightlyinc.com 
  wrote:
   Cant figure out if this is a problem with Twitter4J or the Twitter
   API. I am trying to create an OAuth callback activity, started by a
   RequestToken, but the Request Token request is failing. DOES ANYONE
   KNOW IF GOOGLE HAS MADE THE TWITTER CLIENT AVAILABLE BY OPEN SOURCE
   YET?

   Twitter4J 2.1.2
   Android Froyo 2.2

   package com.sightlyinc.oauth.android;

   import java.util.Date;

   import twitter4j.Twitter;
   import twitter4j.TwitterFactory;
   import twitter4j.http.AccessToken;
   import twitter4j.http.RequestToken;
   import android.app.Activity;
   import android.content.Intent;
   import android.content.SharedPreferences;
   import android.content.SharedPreferences.Editor;
   import android.net.Uri;
   import android.os.Bundle;
   import android.preference.PreferenceManager;
   import android.util.Log;
   import android.view.View;
   import android.view.View.OnClickListener;
   import android.widget.Button;
   import android.widget.EditText;
   import android.widget.Toast;

   public class SightlyOauthActivity extends Activity {

      private static final String TAG =
   SightlyOauthActivity.class.getName();

      private Twitter twitter;
      private RequestToken requestToken;
      private SharedPreferences mSharedPreferences;

      private String CONSUMER_KEY =           yfKRsmTgi8UT8eHoV5Khrw;
      private String CALLBACK_URL =           sightlyoauth://oauth;

      private EditText tweetTextView;
      private Button buttonLogin;

          /** Called when the activity is first created. */
         �...@override
          public void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.main);

                  mSharedPreferences =
                          PreferenceManager.getDefaultSharedPreferences(
                                          getApplicationContext());

                  tweetTextView =
   (EditText)findViewById(R.id.TweetView);
          buttonLogin = (Button)findViewById(R.id.ButtonLogon);
          buttonLogin.setOnClickListener(new OnClickListener() {
                  public void onClick(View v) {
                          askOAuth();
                  }
          });

          }

          /**
           * Open the browser and asks the user to authorize the app.
   Afterwards, we
           * redirect the user back here!
           */
          private void askOAuth() {
                  try {

                          //setup properties, https was attempted and I
   was advised to