Hi OLiE,

I'm not too experienced with Android programming, so am unsure whether your
code is correct or not. But there's something you might want to check on
dev.twitter.com/apps and that's whether your application is set as "browser"
and with a default callback URL set. This is a quirk in our system, such
that if you aren't providing a default callback URL (regardless if it has
anything to do with the actual callback you will use), it will put you into
out of band mode. I think that might be what is happening.

If not, we'll move on to some other possibilities.

Taylor

On Thu, Aug 12, 2010 at 5:22 PM, OLiE <ali.hafi...@gmail.com> wrote:

> Hey guys,
>               I am trying to make an android app for twitter. The
> code that i am using for the login is given below :
>
> package com.twitter;
>
> import org.apache.http.HttpVersion;
> import org.apache.http.client.HttpClient;
> import org.apache.http.conn.ClientConnectionManager;
> import org.apache.http.conn.scheme.PlainSocketFactory;
> import org.apache.http.conn.scheme.Scheme;
> import org.apache.http.conn.scheme.SchemeRegistry;
> import org.apache.http.impl.client.DefaultHttpClient;
> import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
> import org.apache.http.params.BasicHttpParams;
> import org.apache.http.params.HttpConnectionParams;
> import org.apache.http.params.HttpParams;
> import org.apache.http.params.HttpProtocolParams;
> import org.apache.http.protocol.HTTP;
>
> import com.twitter.twitterEngine.TimeLine;
>
> import oauth.signpost.OAuthProvider;
> import oauth.signpost.basic.DefaultOAuthProvider;
> import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
> import oauth.signpost.http.HttpParameters;
> 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.provider.UserDictionary.Words;
> import android.util.Log;
> import android.view.Gravity;
> import android.view.View;
> import android.view.View.OnClickListener;
> import android.widget.Button;
> import android.widget.EditText;
> import android.widget.Toast;
>
> public class Twitter extends Activity implements OnClickListener{
>        /** Called when the activity is first created. */
>        private Button Login;
>        private SharedPreferences prefs;
>        private String prefFile = "twitter_prefs";
>        private final String CALLBACKURL = "myapp://mainactivity";
>        private CommonsHttpOAuthConsumer httpOauthConsumer;
>        private OAuthProvider httpOauthprovider;
>        public final static String consumerKey =                "mykey";
>        public final static String consumerSecret =     "mysecret";
>        @Override
>        public void onCreate(Bundle savedInstanceState) {
>                super.onCreate(savedInstanceState);
>                setContentView(R.layout.main);
>                initViews();
>        }
>        public void initViews()
>        {
>                //initializing the consumer and the provider
>                httpOauthConsumer = new
> CommonsHttpOAuthConsumer(consumerKey,
> consumerSecret);
>                httpOauthprovider = new DefaultOAuthProvider("https://
> api.twitter.com/oauth/request_token",
>                                "https://api.twitter.com/oauth/access_token
> ",
>                                "https://api.twitter.com/oauth/authorize";);
>
>                Login=(Button)findViewById(R.login.LoginButton);
>                Login.setOnClickListener(this);
>        }
>
>        private void doOauth() {
>                try {
>
>                        String authUrl =
> httpOauthprovider.retrieveRequestToken(httpOauthConsumer,
> CALLBACKURL);
>                        this.startActivity(new Intent(Intent.ACTION_VIEW,
> Uri.parse(authUrl)));
>                } catch (Exception e) {
>                        Toast.makeText(this, e.getMessage(),
> Toast.LENGTH_LONG).show();
>                }
>        }
>        public void onClick(View arg0) {
>                // TODO Auto-generated method stub
>                doOauth();
>        }
>        @Override
>        protected void onNewIntent(Intent intent) {
>                // TODO Auto-generated method stub
>                super.onNewIntent(intent);
>                Uri uri = intent.getData();
>                //Check if you got NewIntent event due to Twitter Call back
> only
>                if (uri != null && uri.toString().startsWith(CALLBACKURL)) {
>
>                        String verifier =
> uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER);
>                        prefs = getSharedPreferences(prefFile, 0);
>                        try {
>                                // this will populate token and token_secret
> in consumer
>
>  httpOauthprovider.retrieveAccessToken(httpOauthConsumer,
> verifier);
>                                String userKey =
> httpOauthConsumer.getToken();
>                                String userSecret =
> httpOauthConsumer.getConsumerSecret();
>
>  Log.d("TwitterCheckTwitterActivity","usersecret" + userSecret);
>                                Editor e = prefs.edit();
>                                e.putString("userKey", userKey);
>                                e.putString("userSecret", userSecret);
>                                e.commit();
>                                //start another activity
>
>  Log.d("TwitterCheck","Startingthenewactivity");
>                                Intent i = new Intent(this,TimeLine.class);
>                                startActivity(i);
>                        }
>                        catch(Exception e){
>                                Log.d("", e.getMessage());
>                        }
>
>                }
>        }
>
> }
>
> The error that i get is while retrieving the access token. In the
> logcat i can see that i receive a verifier from twitter. How ever
> during the time of retrieving the access token i keep getting
> D/        (  461): Request token or token secret not set in server
> reply. The service provider you use is probably buggy.
>
> Please help
> Thanks
>

Reply via email to