dinasaif / socialauth-android

Automatically exported from code.google.com/p/socialauth-android
0 stars 0 forks source link

Can't authenticate in android studio #119

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create gradle-based Android Studio project 
2. Single activity with this code, to accomplish share button example

What is the expected output? What do you see instead?

Prompt to allow access to my Twitter account. Then a tweet to my Twitter 
account.

What version of the product are you using? On what operating system?

2.6

Please provide any additional information below.

Complete project attached.

Original issue reported on code.google.com by compton....@gmail.com on 22 Sep 2013 at 10:23

Attachments:

GoogleCodeExporter commented 8 years ago
Note, the gradle-based android studio uses src/main/assets, could this be it?

Original comment by compton....@gmail.com on 22 Sep 2013 at 11:02

GoogleCodeExporter commented 8 years ago
Also note: here's my logcat: 
09-22 16:17:43.150    5269-6137/org.rcompton E/rhsrFigureSocialAuth﹕ 
ResponseListener Error
        org.brickred.socialauth.android.SocialAuthError: URL Authentication error
        at org.brickred.socialauth.android.SocialAuthAdapter$3.run(SocialAuthAdapter.java:530)
        at java.lang.Thread.run(Thread.java:856)

Original comment by compton....@gmail.com on 22 Sep 2013 at 11:17

GoogleCodeExporter commented 8 years ago
More stacktrace :
09-22 18:59:48.481  14034-14051/org.rcompton W/System.err﹕ 
org.brickred.socialauth.android.SocialAuthError: URL Authentication error
09-22 18:59:48.481  14034-14034/org.rcompton I/rhsrFigureSocialAuth﹕ done 
authorize???
09-22 18:59:48.481  14034-14051/org.rcompton W/System.err﹕ at 
org.brickred.socialauth.android.SocialAuthAdapter$3.run(SocialAuthAdapter.java:5
30)
09-22 19:02:37.372  14382-14382/org.rcompton I/rhsrFigureSocialAuth﹕ try to 
construct adapter
09-22 19:02:37.411  14382-14382/org.rcompton D/SocialAuthAdapter﹕ Selected 
provider is twitter
09-22 19:02:37.411  14382-14382/org.rcompton D/SocialAuthAdapter﹕ Loading 
keys and secrets from configuration
09-22 19:02:37.466  14382-14382/org.rcompton I/SocialAuthConfig﹕ Loading 
application configuration
09-22 19:02:37.474  14382-14382/org.rcompton D/SocialAuthAdapter﹕ Starting 
webview for authentication
09-22 19:02:37.474  14382-14382/org.rcompton I/rhsrFigureSocialAuth﹕ twitter 
provider: twitter
09-22 19:02:37.474  14382-14382/org.rcompton I/rhsrFigureSocialAuth﹕ done 
authorize???
09-22 19:02:37.474  14382-14404/org.rcompton D/SocialAuthError﹕ 
org.brickred.socialauth.exception.SocialAuthException: twitter is not a 
provider or valid OpenId URL
09-22 19:02:37.474  14382-14404/org.rcompton E/rhsrFigureSocialAuth﹕ 
ResponseListener Error
        org.brickred.socialauth.android.SocialAuthError: URL Authentication error
        at org.brickred.socialauth.android.SocialAuthAdapter$3.run(SocialAuthAdapter.java:530)
        at java.lang.Thread.run(Thread.java:856)
09-22 19:02:37.474  14382-14404/org.rcompton W/System.err﹕ 
org.brickred.socialauth.android.SocialAuthError: URL Authentication error
09-22 19:02:37.474  14382-14404/org.rcompton W/System.err﹕ at 
org.brickred.socialauth.android.SocialAuthAdapter$3.run(SocialAuthAdapter.java:5
30)

Apparently "twitter" is not a valid URL. But I am initializing the adapter:

        // Add it to Library
        Log.i(LOG_TAG, "try to construct adapter");
        adapter = new SocialAuthAdapter(new ResponseListener());

        adapter.addProvider(Provider.TWITTER, R.drawable.tbird);
        adapter.addCallBack(Provider.TWITTER, "http://www.rcompton.org");

        adapter.authorize(this.getApplicationContext(), Provider.TWITTER);

        Log.i(LOG_TAG, "twitter provider: "+String.valueOf(Provider.TWITTER));

        Log.i(LOG_TAG, "done authorize???");

What am I missing?

Original comment by compton....@gmail.com on 23 Sep 2013 at 2:04

GoogleCodeExporter commented 8 years ago
Hi ,

You are passing the application context. SocialAuth Android requires Activity 
Context

Original comment by vineetmo...@gmail.com on 23 Sep 2013 at 7:11

GoogleCodeExporter commented 8 years ago

I changed from

        adapter.authorize(this.getApplicationContext(), Provider.TWITTER);
to
        adapter.authorize(MainActivity.this, SocialAuthAdapter.Provider.TWITTER);

And still get the errors below. The first happens when it tries the authorize, 
the second happens when I try to click the share button. I've included the 
complete source at the bottom. I've tried my best to get 
http://code.google.com/p/socialauth-android/wiki/sharebuttonexample running, 
but the code found on that link will not compile for me.

09-23 00:57:22.715  22565-22565/org.rcompton D/SocialAuthAdapter﹕ Selected 
provider is twitter
09-23 00:57:22.715  22565-22565/org.rcompton D/SocialAuthAdapter﹕ Loading 
keys and secrets from configuration
09-23 00:57:22.738  22565-22565/org.rcompton I/SocialAuthConfig﹕ Loading 
application configuration
09-23 00:57:22.754  22565-22565/org.rcompton D/SocialAuthAdapter﹕ Starting 
webview for authentication
09-23 00:57:22.754  22565-22565/org.rcompton D/SocialAuthAdapter﹕ Enabling 
button with SocialAuth
09-23 00:57:22.762  22565-22583/org.rcompton D/SocialAuthError﹕ 
org.brickred.socialauth.exception.SocialAuthException: twitter is not a 
provider or valid OpenId URL
09-23 00:57:22.762  22565-22583/org.rcompton E/rhsrFigureSocialAuth﹕ 
ResponseListener Error
        org.brickred.socialauth.android.SocialAuthError: URL Authentication error
        at org.brickred.socialauth.android.SocialAuthAdapter$3.run(SocialAuthAdapter.java:530)
        at java.lang.Thread.run(Thread.java:856)
09-23 00:57:52.316  22565-22565/org.rcompton D/SocialAuthAdapter﹕ Selected 
provider is twitter
09-23 00:57:52.316  22565-22565/org.rcompton D/SocialAuthAdapter﹕ Starting 
webview for authentication
09-23 00:57:52.332  22565-22614/org.rcompton D/SocialAuthError﹕ 
org.brickred.socialauth.exception.SocialAuthException: twitter is not a 
provider or valid OpenId URL
09-23 00:57:52.332  22565-22614/org.rcompton E/rhsrFigureSocialAuth﹕ 
ResponseListener Error
        org.brickred.socialauth.android.SocialAuthError: URL Authentication error
        at org.brickred.socialauth.android.SocialAuthAdapter$3.run(SocialAuthAdapter.java:530)
        at java.lang.Thread.run(Thread.java:856)

package org.rcompton;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import org.brickred.socialauth.android.DialogListener;
import org.brickred.socialauth.android.SocialAuthAdapter;
import org.brickred.socialauth.android.SocialAuthError;
import org.brickred.socialauth.android.SocialAuthListener;

public class MainActivity extends Activity {

    static String LOG_TAG = "rhsrFigureSocialAuth";

    SocialAuthAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        // Welcome Message
        TextView textview = (TextView)findViewById(R.id.editText0);
        textview.setText("Welcome to SocialAuth Demo. We are sharing text SocialAuth Android by share button.");

        //Create Your Own Share Button
        Button shareButton = (Button)findViewById(R.id.tweetButton);
        shareButton.setText("Share");

        // Add it to Library
        adapter = new SocialAuthAdapter(new ResponseListener());
        adapter.addProvider(SocialAuthAdapter.Provider.TWITTER, R.drawable.tbird);
        adapter.addCallBack(SocialAuthAdapter.Provider.TWITTER, "http://www.rcompton.org");

        adapter.authorize(MainActivity.this, SocialAuthAdapter.Provider.TWITTER);

        adapter.enable(shareButton);
    }

    /**
     * Listens Response from Library
     *
     */
    private final class ResponseListener implements DialogListener {

        @Override
        public void onComplete(Bundle values) {

            Log.i(LOG_TAG, "Authentication Successful");

            // Get name of provider after authentication
            String providerName = values.getString(SocialAuthAdapter.PROVIDER);
            Log.i(LOG_TAG, "Provider Name = " + providerName);

            adapter.updateStatus("SocialAuth Android" + System.currentTimeMillis(), new MessageListener(), false);

            Toast.makeText(MainActivity.this, "Message posted on " + providerName, Toast.LENGTH_SHORT).show();

        }

        @Override
        public void onError(SocialAuthError e) {
            Log.e(LOG_TAG, "ResponseListener Error", e);
        }

        @Override
        public void onCancel() {
            Log.i(LOG_TAG, "ResponseListener Cancelled");
        }

        @Override
        public void onBack() {
            Log.e(LOG_TAG, "ResponseListener BachError");

        }
    }

    // To get status of message after authentication
    private final class MessageListener implements SocialAuthListener<Integer> {

        @Override
        public void onExecute(String s, Integer t) {
            Integer status = t;
            if (status.intValue() == 200 || status.intValue() == 201 ||status.intValue() == 204)
                Toast.makeText(MainActivity.this, "Message posted",   Toast.LENGTH_LONG).show();
            else
                Toast.makeText(MainActivity.this, "Message not posted",Toast.LENGTH_LONG).show();
        }

        @Override
        public void onError(org.brickred.socialauth.android.SocialAuthError e) {
            Log.e(LOG_TAG , "MessageListener Error" ,e);
        }
    }
}

Original comment by compton....@gmail.com on 23 Sep 2013 at 8:01

GoogleCodeExporter commented 8 years ago
Hi,

We have not used Android Studio. The provider uses oauth_consumer.properties 
file for getting provider key and secret from assets.

There might be some path issue in Android Studio.

Original comment by vineet.a...@3pillarglobal.com on 4 Oct 2013 at 8:23

GoogleCodeExporter commented 8 years ago
closing this issue , in case you face any issue please post comment

Original comment by vineet.a...@3pillarglobal.com on 4 Oct 2013 at 12:21