Can`t login in twitter with Fabric!

android
fabric
unity

#1

Hello.

I use fabric for Twitter Share function in my Unity game (Android).

I follow all instructions, but I can`t authorize in twitter. But i have my app on dashboard in my fabric account!

Full code:

using UnityEngine;
using Fabric.Twitter;
using System.IO;
using System.Collections;

public class TwitterManager : MonoBehaviour
{
    public void Awake()
    {
        Twitter.Init();
        //  Fabric.Initialize();
    }

    public void Login()
    {
        TwitterSession session = Twitter.Session;
        if (session == null)
        {
            Twitter.LogIn(LoginComplete, LoginFailure);
        }
        else
        {
            LoginComplete(session);
        }
    }

    void LoginComplete(TwitterSession session)
    {
        // Start composer or request email
        Debug.Log("LoginComplete!!!");
        string path = Path.GetFullPath("Art/art.jpg");
        startComposer(session, path);//"http://i.imgur.com/U0l4sn6.jpg"
    }

    public void startComposer(TwitterSession session, string imageUri)
    {
        Card card = new AppCardBuilder()
          .ImageUri(imageUri)
          .GooglePlayId("com.mycompany.mygame");
        //.IPhoneId("123456789")
        //.IPadId("123456789");

        Twitter.Compose(session, card);
    }

    void LoginFailure(ApiError error)
    {
        Debug.Log("code=" + error.code + " msg=" + error.message);
    }
}

Thanks!


#2

Hey @InfoSupperman,

Can you share the console output when you try to login?


#3

Hello. Hello. You mean console from editor?
If yes:

LoginComplete!!!
UnityEngine.Debug:Log(Object)
[Twitter] Would call Twitter Compose on a physical device for user Editor with Image URI C:\Users\777\Desktop\supperman\Art\art.jpg
UnityEngine.Debug:Log(Object)


#4

Thanks @InfoSupperman, are you testing in play mode within the editor? If so, this will not work in that situation.


#5

I understand it. Authorization doesn`t work on phuisical device!


#6

I mean smartphone)


#7

@InfoSupperman Thanks, can you add some additional logging to startComposer and let me know if this fails on the card or compose section? LoginComplete seems to be called and finished so I’m wondering where it’s failing next.


#8

Hi @InfoSupperman,

What platform are you targeting, iOS or Android?


#9

Hi. Android.


#10

Could you launch your app on Android, try to log in, and then share your logcat? We hope that this will help us diagnose the problem.


#11

This is letle modificated script.

 public void Login()
    {
        Console.text += "Call Login(). \n";

        TwitterSession session = Twitter.Session;
        if (session == null)
        {
            Console.text += "Twitter.Session == null. \n";
            Twitter.LogIn(LoginComplete, LoginFailure);
        }
        else
        {
            Console.text += "Twitter.Session != null. \n";
            LoginComplete(session);
        }
    }

    void LoginComplete(TwitterSession session)
    {
        // Start composer or request email
        //Debug.Log("LoginComplete!!!");
        Console.text += "LoginComplete!!! \n";
        string path = Path.GetFullPath("Art/art.jpg");
        Console.text += "Call startComposer(). \n";
        startComposer(session, path);//"http://i.imgur.com/U0l4sn6.jpg"
    }

    public void startComposer(TwitterSession session, string imageUri)
    {
        Console.text += "Start AppCardBuilder(). \n";

        Card card = new AppCardBuilder()
          .ImageUri(imageUri)
          .GooglePlayId("com.vvoss.SupperMan");
        //.IPhoneId("123456789")
        //.IPadId("123456789");

        Console.text += "Call Twitter.Compose(). \n";
        Twitter.Compose(session, card);
        Console.text += "Finish Twitter.Compose(). \n";
    }

    void LoginFailure(ApiError error)
    {
        Debug.Log("code=" + error.code + " msg=" + error.message);
        Console.text += "LoginFailure!!! \n";
    }

And this, how it works on my device!


#12

I’m sorry, I probably did not understand you correctly. I meant Unity for Android platform.


#13

Would it be possible for you to connect your Android device to your computer and run ‘adb logcat’? This might give us a hint as to what’s wrong.


#14

Ок. I`ll try.


#15

This is Error from Log Cat:

07-27 23:00:28.457 10877-10877/? E/NetworkScheduler.SR: Invalid parameter app
07-27 23:00:28.458 10877-10877/? E/NetworkScheduler.SR: Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
07-27 23:00:36.915 589-966/? E/WindowManager: Non floating stack did the function initFloatStackSize
07-27 23:00:37.083 589-2095/? E/WindowManager: Non floating stack did the function initFloatStackSize
07-27 23:00:37.168 589-1635/? E/Sensors: handleToDriver handle(0)
07-27 23:00:37.274 589-589/? E/AudioService: handleConfigurationChanged() createInstance IAudioServiceExt fail
07-27 23:00:37.380 589-604/? E/WindowManager: Non floating stack did the function initFloatStackSize
07-27 23:00:40.187 589-609/? E/ActivityManager: WMS runs the animation too long
07-27 23:00:41.168 10378-10378/? E/Twitter: Invalid json: <?xml version="1.0" encoding="UTF-8"?>
                                            <hash>
                                              <error>Desktop applications only support the oauth_callback value 'oob'</error>
                                              <request>/oauth/request_token</request>
                                            </hash>
                                            
                                            com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 8 path $
                                                at com.google.gson.JsonParser.parse(JsonParser.java:65)
                                                at com.google.gson.JsonParser.parse(JsonParser.java:45)
                                                at com.twitter.sdk.android.core.TwitterApiException.parseApiError(TwitterApiException.java:136)
                                                at com.twitter.sdk.android.core.TwitterApiException.readApiError(TwitterApiException.java:125)
                                                at com.twitter.sdk.android.core.TwitterApiException.<init>(TwitterApiException.java:58)
                                                at com.twitter.sdk.android.core.TwitterApiException.convert(TwitterApiException.java:110)
                                                at com.twitter.sdk.android.core.Callback.failure(Callback.java:45)
                                                at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
                                                at android.os.Handler.handleCallback(Handler.java:808)
                                                at android.os.Handler.dispatchMessage(Handler.java:103)
                                                at android.os.Looper.loop(Looper.java:193)
                                                at android.app.ActivityThread.main(ActivityThread.java:5341)
                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                at java.lang.reflect.Method.invoke(Method.java:515)
                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
                                                at dalvik.system.NativeStart.main(Native Method)
                                             Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 8 path $
                                                at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1572)
                                                at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1421)
                                                at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:544)
                                                at com.google.gson.stream.JsonReader.peek(JsonReader.java:427)
                                                at com.google.gson.JsonParser.parse(JsonParser.java:60)
                                                at com.google.gson.JsonParser.parse(JsonParser.java:45) 
                                                at com.twitter.sdk.android.core.TwitterApiException.parseApiError(TwitterApiException.java:136) 
                                                at com.twitter.sdk.android.core.TwitterApiException.readApiError(TwitterApiException.java:125) 
                                                at com.twitter.sdk.android.core.TwitterApiException.<init>(TwitterApiException.java:58) 
                                                at com.twitter.sdk.android.core.TwitterApiException.convert(TwitterApiException.java:110) 
                                                at com.twitter.sdk.android.core.Callback.failure(Callback.java:45) 
                                                at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53) 
                                                at android.os.Handler.handleCallback(Handler.java:808) 
                                                at android.os.Handler.dispatchMessage(Handler.java:103) 
                                                at android.os.Looper.loop(Looper.java:193) 
                                                at android.app.ActivityThread.main(ActivityThread.java:5341) 
                                                at java.lang.reflect.Method.invokeNative(Native Method) 
                                                at java.lang.reflect.Method.invoke(Method.java:515) 
                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825) 
                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641) 
                                                at dalvik.system.NativeStart.main(Native Method) 
07-27 23:00:41.169 10378-10378/? E/Twitter: Failed to get request token
                                            com.twitter.sdk.android.core.TwitterApiException: 401 Authorization Required
                                                at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:383)
                                                at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
                                                at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
                                                at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
                                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                at retrofit.Platform$Android$2$1.run(Platform.java:142)
                                                at java.lang.Thread.run(Thread.java:848)
07-27 23:00:41.275 10378-10378/? E/Twitter: Authorization completed with an error
                                            com.twitter.sdk.android.core.TwitterAuthException: Failed to get request token
                                                at com.twitter.sdk.android.core.identity.OAuthController$1.failure(OAuthController.java:95)
                                                at com.twitter.sdk.android.core.internal.oauth.OAuth1aService$1.failure(OAuth1aService.java:213)
                                                at com.twitter.sdk.android.core.Callback.failure(Callback.java:45)
                                                at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
                                                at android.os.Handler.handleCallback(Handler.java:808)
                                                at android.os.Handler.dispatchMessage(Handler.java:103)
                                                at android.os.Looper.loop(Looper.java:193)
                                                at android.app.ActivityThread.main(ActivityThread.java:5341)
                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                at java.lang.reflect.Method.invoke(Method.java:515)
                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
                                                at dalvik.system.NativeStart.main(Native Method)
07-27 23:00:41.430 589-589/? E/AudioService: handleConfigurationChanged() createInstance IAudioServiceExt fail
07-27 23:00:41.627 589-956/? E/Sensors: handleToDriver handle(0)
07-27 23:00:41.628 589-956/? E/Sensors: handleToDriver handle(0)
07-27 23:00:41.628 589-956/? E/Sensors: new setDelay handle(0),ns(1000000)m, error(-1), index(2)
07-27 23:00:41.628 589-956/? E/Sensors: new setDelay handle(0),ns(1000000) err! go to hwmsen
07-27 23:00:41.629 589-2095/? E/Sensors: handleToDriver handle(0)
07-27 23:00:41.629 589-2095/? E/Sensors: new setDelay handle(0),ns(20000000)m, error(-1), index(2)
07-27 23:00:41.629 589-2095/? E/Sensors: new setDelay handle(0),ns(20000000) err! go to hwmsen
01-01 00:00:00.000 0-0/? E/Internal: device 'TQ700NL1B565602878' not found

#16

Hey @InfoSupperman,

If you setup a callback, then you should be all set.


#17

I’m sorry, i don’t understand! What do you mean? What a callback?


#18

Here’s a sample here: https://docs.fabric.io/android/twitter/log-in-with-twitter.html#log-in-button of what it would look like on Android.


#19

If I understand you right, I have callback: LoginComplete(), LoginFailure(). I think problem not in this class code. This code works good on my simple testing project! But doesnt work in my game! I think problem in project settings!


#20

Yep, that’s correct - are their some major differences between your test project and main project in terms of project settings or the code for calling it?