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 CONSUMER_SECRET =
"4MIf93Wv35Choa5zXM0gQqIUD8uUFNcvAq1TPuBc";
    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 = intent.getData();
                if (uri != null &&
uri.toString().startsWith(CALLBACK_URL)) {

                        String verifier = uri
                                        .getQueryParameter("oauth_verifier");

                        try {

                                //this user has verified
                                AccessToken accessToken =
 
twitter.getOAuthAccessToken(requestToken, verifier);

                                //save the access token
                                Editor e = mSharedPreferences.edit();
                                e.putString("AccessToken.token",
accessToken.getToken());
                                e.putString("AccessToken.tokenSecret",
accessToken.getTokenSecret());
                                e.putString("AccessToken.screenName",
accessToken.getScreenName());
                                e.commit();

                                // initialize Twitter4J
                                twitter =
                                        new
TwitterFactory().getOAuthAuthorizedInstance(
                                                        CONSUMER_KEY,
CONSUMER_SECRET, accessToken);

                                // create a tweet
                                Date d = new
Date(System.currentTimeMillis());
                                String tweet = "#OAuth working! " +
d.toLocaleString();

                                // send the tweet
                                twitter.updateStatus(tweet);

                                // feedback for the user...
                                tweetTextView.setText(tweet);
                                Toast.makeText(this, tweet,
Toast.LENGTH_LONG).show();
 
buttonLogin.setVisibility(Button.GONE);

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

                }
        }

}

====

07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368): Permission
denied
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):
TwitterException{statusCode=-1, retryAfter=0, rateLimitStatus=null}
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:
316)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:
68)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:
99)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
twitter4j.http.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:
121)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
twitter4j.Twitter.getOAuthRequestToken(Twitter.java:1603)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
com.sightlyinc.oauth.android.SightlyOauthActivity.askOAuth(SightlyOauthActivity.java:
95)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
com.sightlyinc.oauth.android.SightlyOauthActivity.access
$0(SightlyOauthActivity.java:64)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
com.sightlyinc.oauth.android.SightlyOauthActivity
$1.onClick(SightlyOauthActivity.java:54)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
android.view.View.performClick(View.java:2408)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
android.view.View$PerformClick.run(View.java:8816)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
android.os.Handler.handleCallback(Handler.java:587)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
android.os.Handler.dispatchMessage(Handler.java:92)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
android.os.Looper.loop(Looper.java:123)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
android.app.ActivityThread.main(ActivityThread.java:4627)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
java.lang.reflect.Method.invokeNative(Native Method)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
java.lang.reflect.Method.invoke(Method.java:521)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
dalvik.system.NativeStart.main(Native Method)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368): Caused by:
java.net.SocketException: Permission denied
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocketImpl(Native
Method)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocket(OSNetworkSystem.java:
186)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:
265)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
java.net.Socket.checkClosedAndCreate(Socket.java:873)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
java.net.Socket.connect(Socket.java:1020)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:
62)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:
88)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHTTPConnection(HttpURLConn...
927)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl...
909)
07-20 23:04:43.125: ERROR/
com.sightlyinc.oauth.android.SightlyOauthActivity(3368):     at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.sendRequest(HttpURLConnection...
1325) ...

Reply via email to