Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 登录twitter总是转到回调失败方法_Android_Android Volley_Twitter Fabric_Android Twitter - Fatal编程技术网

Android 登录twitter总是转到回调失败方法

Android 登录twitter总是转到回调失败方法,android,android-volley,twitter-fabric,android-twitter,Android,Android Volley,Twitter Fabric,Android Twitter,没有显示错误,但当单击按钮时,它总是转到回调失败方法。Internet处于活动状态,密钥有效。我使用调试器查看以下结果:- E/Twitter: Invalid json: <?xml version="1.0" encoding="UTF-8"?> <hash> <error>Desktop applications only support the oauth_callback value 'oob'</error&g

没有显示错误,但当单击按钮时,它总是转到回调失败方法。Internet处于活动状态,密钥有效。我使用调试器查看以下结果:-

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: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
           at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
           at com.twitter.sdk.android.core.models.SafeListAdapter$1.read(SafeListAdapter.java:45)
           at com.twitter.sdk.android.core.models.SafeMapAdapter$1.read(SafeMapAdapter.java:45)
           at com.google.gson.Gson.fromJson(Gson.java:879)
           at com.google.gson.Gson.fromJson(Gson.java:844)
           at com.google.gson.Gson.fromJson(Gson.java:793)
           at com.google.gson.Gson.fromJson(Gson.java:765)
           at com.twitter.sdk.android.core.TwitterApiException.parseApiError(TwitterApiException.java:111)
           at com.twitter.sdk.android.core.TwitterApiException.readApiError(TwitterApiException.java:96)
           at com.twitter.sdk.android.core.TwitterApiException.<init>(TwitterApiException.java:44)
           at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
           at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
           at android.os.Handler.handleCallback(Handler.java:739)
           at android.os.Handler.dispatchMessage(Handler.java:95)
           at android.os.Looper.loop(Looper.java:148)
           at android.app.ActivityThread.main(ActivityThread.java:5417)
           at java.lang.reflect.Method.invoke(Native Method)
           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
        Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
           at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:387)
           at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:209)
           at com.twitter.sdk.android.core.models.SafeListAdapter$1.read(SafeListAdapter.java:45) 
           at com.twitter.sdk.android.core.models.SafeMapAdapter$1.read(SafeMapAdapter.java:45) 
           at com.google.gson.Gson.fromJson(Gson.java:879) 
           at com.google.gson.Gson.fromJson(Gson.java:844) 
           at com.google.gson.Gson.fromJson(Gson.java:793) 
           at com.google.gson.Gson.fromJson(Gson.java:765) 
           at com.twitter.sdk.android.core.TwitterApiException.parseApiError(TwitterApiException.java:111) 
           at com.twitter.sdk.android.core.TwitterApiException.readApiError(TwitterApiException.java:96) 
           at com.twitter.sdk.android.core.TwitterApiException.<init>(TwitterApiException.java:44) 
           at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42) 
           at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68) 
           at android.os.Handler.handleCallback(Handler.java:739) 
           at android.os.Handler.dispatchMessage(Handler.java:95) 
           at android.os.Looper.loop(Looper.java:148) 
           at android.app.ActivityThread.main(ActivityThread.java:5417) 
           at java.lang.reflect.Method.invoke(Native Method) 
           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
E/Twitter: Failed to get request token
       com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 401
           at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
           at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
           at android.os.Handler.handleCallback(Handler.java:739)
           at android.os.Handler.dispatchMessage(Handler.java:95)
           at android.os.Looper.loop(Looper.java:148)
           at android.app.ActivityThread.main(ActivityThread.java:5417)
           at java.lang.reflect.Method.invoke(Native Method)
           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
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:194)
           at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
           at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
           at android.os.Handler.handleCallback(Handler.java:739)
           at android.os.Handler.dispatchMessage(Handler.java:95)
           at android.os.Looper.loop(Looper.java:148)
           at android.app.ActivityThread.main(ActivityThread.java:5417)
           at java.lang.reflect.Method.invoke(Native Method)
           at   com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
activity_profile.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"


android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.integrationtutorial.ProfileActivity">

    <com.android.volley.toolbox.NetworkImageView
        android:id="@+id/profileImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />


    <TextView
        android:id="@+id/textViewUsername"
        android:layout_margin="@dimen/activity_horizontal_margin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />



</LinearLayout>

CustomVolleyRequest.java

package com.integrationtutorial;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

import com.android.volley.Cache;
import com.android.volley.Network;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.BasicNetwork;
import com.android.volley.toolbox.DiskBasedCache;
import com.android.volley.toolbox.HurlStack;
 import com.android.volley.toolbox.ImageLoader;

public class CustomVolleyRequest {

private static CustomVolleyRequest customVolleyRequest;
private static Context context;
private RequestQueue requestQueue;
private ImageLoader imageLoader;

private CustomVolleyRequest(Context context) {
    this.context = context;
    this.requestQueue = getRequestQueue();

    imageLoader = new ImageLoader(requestQueue,
            new ImageLoader.ImageCache() {
                private final LruCache<String, Bitmap>
                        cache = new LruCache<String, Bitmap>(20);

                @Override
                public Bitmap getBitmap(String url) {
                    return cache.get(url);
                }

                @Override
                public void putBitmap(String url, Bitmap bitmap) {
                    cache.put(url, bitmap);
                }
            });
}

public static synchronized CustomVolleyRequest getInstance(Context context)     {
    if (customVolleyRequest == null) {
        customVolleyRequest = new CustomVolleyRequest(context);
    }
    return customVolleyRequest;
}

public RequestQueue getRequestQueue() {
    if (requestQueue == null) {
        Cache cache = new DiskBasedCache(context.getCacheDir(), 10 * 1024 * 1024);
        Network network = new BasicNetwork(new HurlStack());
        requestQueue = new RequestQueue(cache, network);
        requestQueue.start();
    }
    return requestQueue;
}

public ImageLoader getImageLoader() {
    return imageLoader;
}
}
package.com.integrationtutorial;
导入android.content.Context;
导入android.graphics.Bitmap;
导入android.support.v4.util.LruCache;
导入com.android.volley.Cache;
导入com.android.volley.Network;
导入com.android.volley.RequestQueue;
导入com.android.volley.toolbox.BasicNetwork;
导入com.android.volley.toolbox.DiskBasedCache;
导入com.android.volley.toolbox.HurlStack;
导入com.android.volley.toolbox.ImageLoader;
公共类自定义截击请求{
私有静态CustomVolleyRequest CustomVolleyRequest;
私有静态语境;
私有请求队列请求队列;
私有图像加载器;
私有CustomVolleyRequest(上下文){
this.context=上下文;
this.requestQueue=getRequestQueue();
imageLoader=新的imageLoader(请求队列,
新建ImageLoader.ImageCache(){
私人决赛
缓存=新的LruCache(20);
@凌驾
公共位图getBitmap(字符串url){
返回cache.get(url);
}
@凌驾
公共位图(字符串url、位图){
cache.put(url、位图);
}
});
}
公共静态同步CustomVolleyRequest getInstance(上下文){
if(customVolleyRequest==null){
customVolleyRequest=新customVolleyRequest(上下文);
}
返回客户截击请求;
}
公共请求队列getRequestQueue(){
if(requestQueue==null){
Cache Cache=new DiskBasedCache(context.getCacheDir(),10*1024*1024);
网络=新的基本网络(new HurlStack());
requestQueue=新的requestQueue(缓存、网络);
requestQueue.start();
}
返回请求队列;
}
公共ImageLoader getImageLoader(){
返回图像加载器;
}
}
安卓清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.integrationtutorial">
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data
        android:name="io.fabric.ApiKey"
        android:value="KEY_HERE" />
</application>

<uses-permission android:name="android.permission.INTERNET" />
</manifest>

当我的设备上没有安装Twitter应用程序时,我遇到了相同的错误

桌面应用程序仅支持oauth_回调值 “哦” /oauth/request\u令牌

但是当Twitter应用程序安装在设备上时,Twitter登录就正常工作了

若要在设备上未安装Twitter应用程序时使Twitter登录正常工作,请对应用程序进行以下更改:

转到应用程序中的“权限”选项卡,将访问权限更改为“读、写和访问直接消息”,并在“其他权限”中启用“向用户请求电子邮件地址”


最后,单击“更新设置”保存更改。

尝试此链接,所有步骤都已完成。此链接将为您提供twitter登录@AmeeJoshi的完整示例代码。我正在查找代码中的错误。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"


android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.integrationtutorial.ProfileActivity">

    <com.android.volley.toolbox.NetworkImageView
        android:id="@+id/profileImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />


    <TextView
        android:id="@+id/textViewUsername"
        android:layout_margin="@dimen/activity_horizontal_margin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />



</LinearLayout>
package com.integrationtutorial;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

import com.android.volley.Cache;
import com.android.volley.Network;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.BasicNetwork;
import com.android.volley.toolbox.DiskBasedCache;
import com.android.volley.toolbox.HurlStack;
 import com.android.volley.toolbox.ImageLoader;

public class CustomVolleyRequest {

private static CustomVolleyRequest customVolleyRequest;
private static Context context;
private RequestQueue requestQueue;
private ImageLoader imageLoader;

private CustomVolleyRequest(Context context) {
    this.context = context;
    this.requestQueue = getRequestQueue();

    imageLoader = new ImageLoader(requestQueue,
            new ImageLoader.ImageCache() {
                private final LruCache<String, Bitmap>
                        cache = new LruCache<String, Bitmap>(20);

                @Override
                public Bitmap getBitmap(String url) {
                    return cache.get(url);
                }

                @Override
                public void putBitmap(String url, Bitmap bitmap) {
                    cache.put(url, bitmap);
                }
            });
}

public static synchronized CustomVolleyRequest getInstance(Context context)     {
    if (customVolleyRequest == null) {
        customVolleyRequest = new CustomVolleyRequest(context);
    }
    return customVolleyRequest;
}

public RequestQueue getRequestQueue() {
    if (requestQueue == null) {
        Cache cache = new DiskBasedCache(context.getCacheDir(), 10 * 1024 * 1024);
        Network network = new BasicNetwork(new HurlStack());
        requestQueue = new RequestQueue(cache, network);
        requestQueue.start();
    }
    return requestQueue;
}

public ImageLoader getImageLoader() {
    return imageLoader;
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.integrationtutorial">
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data
        android:name="io.fabric.ApiKey"
        android:value="KEY_HERE" />
</application>

<uses-permission android:name="android.permission.INTERNET" />
</manifest>