首页 > 解决方案 > Twitter 身份验证不起作用,并且没有显示具有用户名的主屏幕

问题描述

我正在尝试通过https://developer.twitter.com/获取 Auth 用户

当我单击登录时,我使用模拟器在终端中找到了以下代码:

I/twitterlogints( 7102): WaitForGcToComplete blocked Background on None for 5.254ms
I/twitterlogints( 7102): Background young concurrent copying GC freed 4859(347KB) AllocSpace objects, 4(80KB) LOS objects, 44% free, 2094KB/3800KB, paused 9.057ms total 138.163ms
I/WebViewFactory( 7102): Loading com.google.android.webview version 83.0.4103.106 (code 410410681)
I/twitterlogints( 7102): The ClassLoaderContext is a special shared library.
D/nativeloader( 7102): classloader namespace configured for unbundled product apk. library_path=/product/app/WebViewGoogle/lib/x86:/product/app/WebViewGoogle/WebViewGoogle.apk!/lib/x86:/product/app/TrichromeLibrary/TrichromeLibrary.apk!/lib/x86:/product/lib:/system/product/lib
I/twitterlogints( 7102): The ClassLoaderContext is a special shared library.
D/nativeloader( 7102): classloader namespace configured for unbundled product apk. library_path=/product/app/WebViewGoogle/lib/x86:/product/app/WebViewGoogle/WebViewGoogle.apk!/lib/x86:/product/app/TrichromeLibrary/TrichromeLibrary.apk!/lib/x86:/product/lib:/system/product/lib
I/cr_VariationsUtils( 7102): Requesting new seed from IVariationsSeedServer
I/cr_LibraryLoader( 7102): Loaded native library version number "83.0.4103.106"
I/cr_CachingUmaRecorder( 7102): Flushed 3 samples from 3 histograms.
I/TetheringManager( 7102): registerTetheringEventCallback:com.example.twitterlogintst
W/chromium( 7102): [WARNING:dns_config_service_posix.cc(341)] Failed to read DnsConfig.
W/twitterlogints( 7102): Accessing hidden method Lcom/android/org/conscrypt/ConscryptEngineSocket;->setUseSessionTickets(Z)V (greylist-max-q,core-platform-api, reflection, denied)
W/twitterlogints( 7102): Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setUseSessionTickets(Z)V (greylist-max-q,core-platform-api, reflection, denied)
W/twitterlogints( 7102): Accessing hidden method Lcom/android/org/conscrypt/AbstractConscryptSocket;->setUseSessionTickets(Z)V (greylist-max-q, reflection, denied)
W/twitterlogints( 7102): Accessing hidden method Lcom/android/org/conscrypt/ConscryptEngineSocket;->setHostname(Ljava/lang/String;)V (greylist-max-q,core-platform-api, reflection, denied)
W/twitterlogints( 7102): Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setHostname(Ljava/lang/String;)V (greylist-max-q,core-platform-api, reflection, denied)
W/twitterlogints( 7102): Accessing hidden method Lcom/android/org/conscrypt/AbstractConscryptSocket;->setHostname(Ljava/lang/String;)V (greylist-max-q, reflection, denied)
W/twitterlogints( 7102): Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setAlpnProtocols([B)V (greylist-max-q,core-platform-api, reflection, denied)
W/twitterlogints( 7102): Accessing hidden method Lcom/android/org/conscrypt/AbstractConscryptSocket;->setAlpnProtocols([B)V (greylist-max-q, reflection, denied)
I/Choreographer( 7102): Skipped 31 frames!  The application may be doing too much work on its main thread.
I/twitterlogints( 7102): Background concurrent copying GC freed 16873(1104KB) AllocSpace objects, 6(120KB) LOS objects, 49% free, 2772KB/5544KB, paused 7.674ms total 688.799ms
W/twitterlogints( 7102): Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->getAlpnSelectedProtocol()[B (greylist-max-q,core-platform-api, reflection, denied)
W/twitterlogints( 7102): Accessing hidden method Lcom/android/org/conscrypt/AbstractConscryptSocket;->getAlpnSelectedProtocol()[B (greylist-max-q, reflection, denied)
W/twitterlogints( 7102): Accessing hidden method Landroid/media/AudioManager;->getOutputLatency(I)I (greylist, reflection, allowed)
D/HostConnection( 7102): HostConnection::get() New Host Connection established 0xf17a8100, tid 7266
W/cr_media( 7102): Requires BLUETOOTH permission
D/HostConnection( 7102): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_3_0 
D/EGL_emulation( 7102): eglCreateContext: 0xf17aa710: maj 3 min 0 rcv 3
D/EGL_emulation( 7102): eglMakeCurrent: 0xf17aa710: ver 3 0 (tinfo 0xbf4f5730) (first time)
I/VideoCapabilities( 7102): Unsupported profile 4 for video/mp4v-es
W/cr_MediaCodecUtil( 7102): HW encoder for video/avc is not available on this device.
D/EGL_emulation( 7102): eglCreateContext: 0xf17a7370: maj 3 min 0 rcv 3
I/AssistStructure( 7102): Flattened final assist data: 2692 bytes, containing 1 windows, 7 views
I/AssistStructure( 7102): Flattened final assist data: 2724 bytes, containing 1 windows, 7 views

而这个在使用真实设备时:

I/zygote64(12598): Do partial code cache collection, code=61KB, data=43KB
I/zygote64(12598): After code cache collection, code=61KB, data=43KB
I/zygote64(12598): Increasing code cache capacity to 256KB
W/ResourceType(12598): No package identifier when getting name for resource number 0x00000000
I/WebViewFactory(12598): Loading com.android.chrome version 85.0.4183.127 (code 418312773)
W/zygote64(12598): miui_dex2oat: OatFile: /data/app/com.android.chrome-qvjtBkRc2acyF4nG14ESjA==/oat/arm64/base.odex Compiler-Filter = speed
W/zygote64(12598): miui_dex2oat: oat file of /data/app/com.android.chrome-qvjtBkRc2acyF4nG14ESjA==/split_config.en.apk is not exists
W/zygote64(12598): miui_dex2oat: OatFile: /data/app/com.android.chrome-qvjtBkRc2acyF4nG14ESjA==/oat/arm64/split_extra_icu.odex Compiler-Filter = speed
W/ResourceType(12598): No package identifier when getting name for resource number 0x00000000
W/ResourceType(12598): No package identifier when getting name for resource number 0x00000000
I/cr_LibraryLoader(12598): Loaded native library version number "85.0.4183.127"
I/cr_CachingUmaRecorder(12598): Flushed 5 samples from 5 histograms.
W/ResourceType(12598): Failure getting entry for 0x7f1305b7 (t=18 e=1463) (error -2147483647)
E/chromium(12598): [ERROR:filesystem_posix.cc(62)] mkdir /data/user/0/com.example.twitterlogintst/cache/WebView/Crashpad: No such file or directory (2)
W/chromium(12598): [WARNING:dns_config_service_posix.cc(342)] Failed to read DnsConfig.
D/EgretLoader(12598): EgretLoader(Context context)
D/EgretLoader(12598): The context is not activity
W/ContentCatcher(12598): Failed to notify a WebView
W/Choreographer(12598): Already have a pending vsync event.  There should only be one at a time.
W/cr_media(12598): Requires BLUETOOTH permission
I/AssistStructure(12598): Flattened final assist data: 3596 bytes, containing 1 windows, 7 views
I/zygote64(12598): Do full code cache collection, code=122KB, data=88KB
I/zygote64(12598): After code cache collection, code=117KB, data=70KB
I/zygote64(12598): Do partial code cache collection, code=117KB, data=77KB
I/zygote64(12598): After code cache collection, code=117KB, data=77KB
I/zygote64(12598): Increasing code cache capacity to 512KB
W/Looper  (12598): Slow Frame: doFrame is 339ms late

这是以下身份验证设置:

在此处输入图像描述 在此处输入图像描述

当我在按下登录后尝试进行身份验证时,它会以下面的屏幕结束,并且不会返回主屏幕以显示用户名......:

在此处输入图像描述

这是下面的代码:

import 'package:flutter/material.dart';
import 'package:flutter_twitter_login/flutter_twitter_login.dart';

void main() {
  runApp(MaterialApp(
    debugShowCheckedModeBanner: false,
    home: TwitterLoginScreen(),
  ));
}

class TwitterLoginScreen extends StatefulWidget {
  @override
  _TwitterLoginScreenState createState() => _TwitterLoginScreenState();
}

class _TwitterLoginScreenState extends State<TwitterLoginScreen> {
  static final TwitterLogin twitterLogin = TwitterLogin(
    consumerKey: 'consumerKey',
    consumerSecret: 'consumerSecret',
  );

  String _title="";

  void _login() async {
    final TwitterLoginResult result = await twitterLogin.authorize();
    String Message;

    switch (result.status) {
      case TwitterLoginStatus.loggedIn:
        Message = 'Logged in! username: ${result.session.username}';
        break;
      case TwitterLoginStatus.cancelledByUser:
        Message = 'Login cancelled by user.';
        break;
      case TwitterLoginStatus.error:
        Message = 'Login error: ${result.errorMessage}';
        break;
    }

    setState(() {
      _title = Message;
    });
  }

  void _logout() async {
    await twitterLogin.logOut();

    setState(() {
      _title = 'Logged out.';
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: const Color(0xFF167F67),
          title: Text('Twitter login sample'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(_title),
              _title.isEmpty
                  ? ElevatedButton(
                child: Text('Log in'),
                onPressed: _login,
              )
                  : SizedBox(
                width: 0.0,
              ),
              _title.isNotEmpty?  ElevatedButton(
                child: Text('Log out'),
                onPressed: _logout,
              ):SizedBox(width: 0.0,),
            ],
          ),
        ),
      ),
    );
  }
}

标签: flutterdart

解决方案


推荐阅读