登录twitter总是进入回调失败方法

2023-12-25

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

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)

主要活动

package com.integrationtutorial;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import com.twitter.sdk.android.Twitter;
import com.twitter.sdk.android.core.Callback;
import com.twitter.sdk.android.core.Result;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.twitter.sdk.android.core.TwitterAuthToken;
import com.twitter.sdk.android.core.TwitterException;
import com.twitter.sdk.android.core.TwitterSession;
import com.twitter.sdk.android.core.identity.TwitterLoginButton;
import com.twitter.sdk.android.core.models.User;

import io.fabric.sdk.android.Fabric;
import retrofit2.Call;

public class MainActivity extends AppCompatActivity
{

//This is your KEY and SECRET
//And it would be added automatically while the configuration
private static final String TWITTER_KEY = "KEY_HERE";
private static final String TWITTER_SECRET = "KEY_HERE";

//Tags to send the username and image url to next activity using intent
public static final String KEY_USERNAME = "username";
public static final String KEY_PROFILE_IMAGE_URL = "image_url";

//Twitter Login Button
TwitterLoginButton twitterLoginButton;


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

    //Initializing TwitterAuthConfig, these two line will also added automatically while configuration we did
    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.with(this, new Twitter(authConfig));

    setContentView(R.layout.activity_main);

    //Initializing twitter login button
    twitterLoginButton = (TwitterLoginButton) findViewById(R.id.twitterLogin);

    //Adding callback to the button
    twitterLoginButton.setCallback(new Callback<TwitterSession>()
    {
        @Override
        public void success(Result<TwitterSession> result)
        {
            //If login succeeds passing the Calling the login method and passing Result object
            login(result);
        }

        @Override
        public void failure(TwitterException exception) {
            //If failure occurs while login handle it here
            Toast.makeText(getApplicationContext(),"Login with Twitter failure",Toast.LENGTH_LONG).show();

        }
    });

}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    //Adding the login result back to the button
    twitterLoginButton.onActivityResult(requestCode, resultCode, data);
}

//The login function accepting the result object
public void login(Result<TwitterSession> result) {

    //Creating a twitter session with result's data
    TwitterSession session = result.data;

    //Getting the username from session
    final String username = session.getUserName();

    //This code will fetch the profile image URL
    //Getting the account service of the user logged in
    Call<User> call= Twitter.getApiClient(session).getAccountService().verifyCredentials(true, false);
    call.enqueue(new Callback<User>()
    {
                @Override
                public void failure(TwitterException e)
                {
                    //If any error occurs handle it here
                }

                @Override
                public void success(Result<User> userResult)
                {
                    //If it succeeds creating a User object from userResult.data
                    User user = userResult.data;

                    //Getting the profile image url
                    String profileImage = user.profileImageUrl.replace("_normal", "");

                    //Creating an Intent
                    Intent intent = new Intent(MainActivity.this, ProfileActivity.class);

                    //Adding the values to intent
                    intent.putExtra(KEY_USERNAME,username);
                    intent.putExtra(KEY_PROFILE_IMAGE_URL, profileImage);

                    //Starting intent
                    startActivity(intent);
                }

    });
}
}

活动主文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
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.MainActivity">


<com.twitter.sdk.android.core.identity.TwitterLoginButton
    android:id="@+id/twitterLogin"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical" />

</RelativeLayout>

ProfileActivity.java

package com.integrationtutorial;

import android.content.Intent; 
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;

public class ProfileActivity extends AppCompatActivity {

//Image Loader object
private ImageLoader imageLoader;

//NetworkImageView Ojbect
private NetworkImageView profileImage;

//TextView object
private TextView textViewUsername;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);

    //Initializing views
    profileImage = (NetworkImageView) findViewById(R.id.profileImage);
    textViewUsername = (TextView) findViewById(R.id.textViewUsername);

    //Getting the intent
    Intent intent = getIntent();

    //Getting values from intent
    String username = intent.getStringExtra(MainActivity.KEY_USERNAME);
    String profileImageUrl = intent.getStringExtra(MainActivity.KEY_PROFILE_IMAGE_URL);

    //Loading image
    imageLoader = CustomVolleyRequest.getInstance(this).getImageLoader();
    imageLoader.get(profileImageUrl, ImageLoader.getImageListener(profileImage, R.mipmap.ic_launcher, android.R.drawable.ic_dialog_alert));
    profileImage.setImageUrl(profileImageUrl, imageLoader);

    //Setting the username in textview
    textViewUsername.setText("@"+username);
}
}

活动配置文件.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;
}
}

安卓清单

<?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_callback 值 '哦' /oauth/request_token

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

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

https://apps.twitter.com/app/13917465/permissions https://apps.twitter.com/app/13917465/permissions

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

登录twitter总是进入回调失败方法 的相关文章

  • 使用 xamarin 和 c# 更改 android 上的cultureinfo

    我调用自定义方法来动态地将当前文化信息切换为法语 fr 像这样 但在调用该方法后 我的 Android 应用程序仍然使用默认区域性 en 但在调试模式下 区域性似乎没问题 我的文件夹没问题 我两者都有 并且字符串值已配置 文件夹 resou
  • 可以挂载未加密的 obb 但出现加密错误 21

    这与 kitkat bug 无关 我正在 4 4 2 中测试 我可以毫无问题地挂载 obb 文件 问题是当尝试对加密的 obb 执行相同操作时 我在 Windows 中使用 jobb 如下 jobb d my folder o exp ob
  • 现实世界中的 JavaCard 3?

    我目前正在从事我的文凭工作 部分工作包括开发JavaCard常规小程序SIM牌 第一个选项是使用JavaCard2 X API并使用APDU与小程序通信的命令 这可能非常棘手 因为我需要为 android 开发客户端应用程序 它将与这个小程
  • OpenGL ES 2.0 中的透明对象

    所以我一直在 Android 上使用 OpenGL ES 2 0 但现在遇到了一个我无法解决的问题 提前道歉 看来我还不能发布两个以上的链接 所以我把我的三张图片放在 Photobucket 相册中 我正在尝试创建一个由透明区域 彩色玻璃
  • 更新房间迁移的行

    是否可以编写迁移来更新某个表的所有先前数据 我正在为我的房间数据开发加密 如果我可以在迁移后加密所有行 那就太好了 那么 在定义迁移时 您可以访问支持SQLite数据库 https developer android com referen
  • 如何在同一个列表视图中同时实现ontouch和onfling?

    我有一个listview并实现了onclick和onfling 问题是当我进行fling 从左向右滑动 时 listview的onclick事件也被执行 如何克服这个问题 如何区分列表视图中的触摸 点击 和滑动 滑动 listClickLi
  • eclipse 找不到我的 sdk 文件夹

    我已经在 Windows 7 上的 eclipse helios 上安装了 android sdk 和 adt 插件 但是 当我进入首选项时 我在定位 sdk 位置时遇到了问题 我的 SDK 位置是 C Program Files Andr
  • LibGDX 闪烁

    我已经使用 LibGDX UI 设置来启动一个项目 我在实现 ApplicationListener 中唯一拥有的是 public void create setScreen new LoadingScreen this 这应该会触发 Lo
  • 以编程方式更改小部件布局

    假设我有两个小部件布局 Layout1 和 Layout2 小部件的默认值是 Layout1 但我允许用户选择 他们希望小部件采用哪种布局 所以如果用户更改为 Layout2 如何以编程方式将布局更改为 Layout2 小部件没有像活动那样
  • Android MapView v2 黑屏

    我一直在尝试实现 android 的 MapView v2 除了这个错误之外 我让它工作得很好 This is what it looks like when I load the app from scratch 如您所见 没有任何问题
  • AWS Cognito-获取带有ID的用户信息

    有没有什么方法可以获取 AWS Cognito 池 在 Android 上 中未登录的用户的信息 并知道他的 ID 我尝试了该代码 AppHelper getPool getUser username getDetailsInBackgro
  • 如何在phonegap中同时使用相机API选择多个图像?

    如何同时选择或拾取多个图像phonegap camera API使用时Camera DestinationType FILE URI 我一次只能选择一张图像 我可以使用以下命令在 SD 卡中选择多个文件 包括 txt pdf this ht
  • Google Play 将我的应用程序版本显示为“随设备而变化”

    我最近在 Google Play 商店更新了我的应用程序 在我的 Play 商店应用程序页面中 版本显示为因设备而异我没有上传多个 apk 而是使用单个 apk 更新了我的应用程序 那么为什么它显示版本为因设备而异 是否有任何设置可以删除此
  • 无法将图像从 url 存储到 SD 卡

    我想将图像存储在 mnt sdcard 中 package com Downld file frm net import java io BufferedInputStream import java io File import java
  • 如何使用 Android Volley API?

    我正在考虑在我的下一个项目中实现 Android Volley 库 关于 Volley 的 Google IO 演示 http www youtube com watch v yhv8l9F44qo 但是 我还没有找到该库的任何重要的 AP
  • Web 服务凭证 - OpenID/Android AccountManager?

    我正在构建一个网络服务 并想使用用户的谷歌帐户凭据 该服务在 GAE 上运行 并将有一个 Web 客户端和一个 Android 本机客户端 这是我第一次尝试类似的事情 我一直在阅读有关 OpenID 和 Android AccountMan
  • ConstraintLayout 源代码位于哪里?

    哪里可以找到android的源代码ConstraintLayout 我在支持框架存储库甚至谷歌搜索中都找不到它 它的源代码在这里 https android googlesource com platform frameworks opt
  • Android 依赖项 com.google.firebase:firebase-core 编译 (12.0.1) 和运行时 (11.4.2) 的版本不同

    这是我的项目 Gradle 依赖项 classpath com android tools build gradle 3 1 0 classpath com google gms google services 3 0 0 classpat
  • onActivityResult() Intent 数据始终为 null

    有人可以告诉我为什么Intent data总是为空 Override protected void onActivityResult int requestCode int resultCode Intent data super onAc
  • INSTALL_FAILED_NO_MATCHING_ABIS:无法提取本机库,res = -113设备

    当我在 android 8 0 设备中执行 android 项目时 我收到错误 INSTALL FAILED NO MATCHING ABIS 无法提取本机库 res 113 错误图像 https i stack imgur com 3kb

随机推荐