Android requestEmail Fabric SDK

android
fabric
email

#1

Hi,

I integrate Twitter LogIn in my app. I’m using:
Android Studio 1.4.1
twitter SDK (compile(‘com.twitter.sdk.android:twitter:1.8.0@aar’) )

I retrieve the correct user’s information (Username, profileImageUrl,token, segret, screenName, etc).
I have the additional permission for read the email:

I call the function:
authClient.requestEmail(session, new Callback() {
@Override
public void success(Result result) {
// Do something with the result, which provides the email address
Log.i(Constants.TAG, "EMAIL: " + result.toString());
retry_information_TW();

                }

                @Override
                public void failure(TwitterException exception) {
                    // Do something on failure
                    Log.i(Constants.TAG, "ERROR: " + exception.getMessage());
                }
            });

But in this point, The program return :

Your application may not have access to email addresses or the user may not have an email address. To request access, please visit https://support.twitter.com/forms/platform.

I don’t understand , where is my mistake ?

Michele


#2

Hey @LAB_4_IT_TEST,

That seems a bit odd. Can you run a clean of your project and let me know if that clears it up? If not, do you see different Twitter Consumer Keys present in your AndroidManifest and MainActivity?

-Mike


#3

Hi Mike,

I have a bit confusion about the difference between <io.fabric.ApiKey> in AndroidManifest and Twitter Consumer Key in my Activity.
In AndroidManifest I have <io.fabric.ApiKey> and in my app I call with different TWITTER KEY and segret

TwitterAuthConfig authConfig = new TwitterAuthConfig(Constants.TWITTER_KEY, Constants.TWITTER_SECRET);
Fabric.with(this, new Twitter(authConfig));
client = new TwitterAuthClient();

I haven’t defined nothing in AndroidManifest…
I retry information to Manage Fabric Application, In this case I have a different CLIENT APPLICATION ID.

Is it the mistake?

Michele

P.S. My name (in Italian) is like yours (Mike or Michael in English…)


#4

Thanks, you should use your Twitter Consumer Key that you made via apps.twitter.com. In your AndroidManifest, Build.gradle or fabric.properties file, you should have your API key listed.

For example, in my AndroidManifest, I have:

<application>
    ...
    <meta-data
        android:name="io.fabric.ApiKey"
        android:value="TheValueOfMyApiKey" />
</application>

otherwise my code is similar to yours.


Fabric Android: RequestEmail not get the user email
#5

Hi Mike,

Thanks for your reply…
I correct my code with your suggestion:

in AndroidManifest.xml

In my activity:
private TwitterAuthClient client;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TwitterAuthConfig authConfig = new TwitterAuthConfig(Constants.TWITTER_KEY, Constants.TWITTER_SECRET);
    Fabric.with(this, new Twitter(authConfig));
    client = new TwitterAuthClient();

}

The TWITTER_KEY and the Key in Android Manifest is the same.

I have a function:

public void LoginTwitter(){

    TwitterSession session = Twitter.getSessionManager().getActiveSession();

    if (session==null){
        client.authorize(this, new Callback<TwitterSession>() {
        @Override
        public void success(Result<TwitterSession> twitterSessionResult) {
            Log.i(Constants.TAG, "ONSUCCESS");

            TwitterSession session = Twitter.getSessionManager().getActiveSession();
            TwitterAuthToken authToken = session.getAuthToken();
            TwitterAuthClient authClient = new TwitterAuthClient();
            //retry_information_TW();


            authClient.requestEmail(session, new Callback<String>() {
                @Override
                public void success(Result<String> result) {
                    // Do something with the result, which provides the email address
                    Log.i(Constants.TAG, "EMAIL: " + result.toString());
                    retry_information_TW();

                }

                @Override
                public void failure(TwitterException exception) {
                    // Do something on failure
                    Log.i(Constants.TAG, "ERROR: " + exception.getMessage());
                    retry_information_TW();
                }
            });



        }

        @Override
        public void failure(TwitterException e) {
            Log.i(Constants.TAG, "ERR:" + e.getMessage());
        }
    });

    }else {
        TwitterAuthToken authToken = session.getAuthToken();

        Log.i(Constants.TAG, "TW SEGRET:" + authToken.secret);
        Log.i(Constants.TAG, "TW TOKEN:" + authToken.token);

        retry_information_TW();
    }

}

The Autenthication resolve without problem, but when I request the email , I have the same problem:

Your application may not have access to email addresses or the user may not have an email address.

Have you any idea about?

Thanks

Michele


#6

It’s possible that the user doesn’t have an email address associated with their Twitter account. If you’re testing against your account, do you have an address in your account?


#7

Hi Mike,

I have found the problem.
In my twitter account, the app was already registred with old permission (Read, Write, but not reading Email).

I push the button “Revoca Adesso” (in Italian ), and I remake the connection with my app.

When I call:

            TwitterSession session = Twitter.getSessionManager().getActiveSession();
            TwitterAuthToken authToken = session.getAuthToken();
            TwitterAuthClient authClient = new TwitterAuthClient();

            authClient.requestEmail(session, new Callback<String>() {
                @Override
                public void success(Result<String> result) {
                    // Do something with the result, which provides the email address
                    Log.i(Constants.TAG, "EMAIL: " + result.data.toString());
                    retry_information_TW(result.data.toString());
                }

                @Override
                public void failure(TwitterException exception) {
                    // Do something on failure
                    Log.i(Constants.TAG, "ERROR: " + exception.getMessage());
                    retry_information_TW("");
                }
            });



        }

        @Override
        public void failure(TwitterException e) {
            Log.i(Constants.TAG, "ERR:" + e.getMessage());
        }
    });

Now, I have the Email…

Thanks for your help.

Michele


#8

Thanks for letting me know Michele and happy coding!


#9