flutter: HttpException: Failed禁止使用twitter插件



我试图在我的应用程序中实现twitter登录,但它不起作用,在AppResult对象中返回errorMessage。有人知道解决办法吗?

我使用的包是twitter_login: ^ 4.2.3

重火力点:firebase_core: ^ 1.11.0firebase_auth: ^ 3.3.5

Twitter配置(用户认证设置页面):

  • OAuth 1.0a启用(它是合适的插件吗?)
  • 用户请求邮件:disabled
  • App权限:Read
  • Callback URI: https://project-name.firebaseapp.com/__/auth/handler
  • 网址:https://www.google.com/

重火力点配置:

  • 推特认证启用
  • api key set(检查了10次)
  • api secret set(同上)
  • Android清单:

活动标签内:

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "example://gizmos” -->
<!-- Registered Callback URLs in TwitterApp -->
<data android:scheme="https" android:host="app-name.firebaseapp.com" />
<!-- host is option -->
</intent-filter>

活动标签后:

<meta-data android:name="flutterEmbedding" android:value="2" />

代码本身:

final twitterLogin = TwitterLogin(
apiKey: '123 it's the same one',
apiSecretKey: 'proper one',
redirectURI: 'https://app-name.firebaseapp.com/__/auth/handler');
final authResult = await twitterLogin.login();
print(authResult.errorMessage); // prints out HttpException: Failed Forbidden

代码打开了带有身份验证的链接,但在点击"授权应用"之后,它返回到应用并返回errorMessage"HttpException: Failed forbidden";另外,authToken和authTokenSecret都为空。

如果你需要任何额外的信息,请告诉我!

您正在获取被禁止的http异常。因此,在官方文档中它说-

请求被理解,但已被拒绝或不允许访问。附带的错误信息将解释原因。

解为-

检查您的开发人员帐户是否包含对您试图使用的端点的访问权限。你可能还需要让你的应用程序允许列表(例如用户粘性API或广告API)或注册访问权限。

你可以查看- Twitter API文档

希望有帮助。

所以,经过一点点挖掘,我找到了我问题的答案。为了使它工作,我做了以下操作:

  1. 将android方案更改为appname://

  2. 删除android主机

    <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE"/>
    <!-- Accepts URIs that begin with "example://gizmos” -->
    <!-- Registered Callback URLs in TwitterApp -->
    <data android:scheme="appname" />
    <!-- host is option -->
    </intent-filter>
    
  3. 将twitter配置中的重定向url更改为appname://

  4. 获得了twitter门户的提升访问权限

  5. 将loginV2函数与OAuth2一起使用,而不是OAuth1

    Future<UserCredential> _signInWithTwitter() async {
    // Create a TwitterLogin instance
    
    final twitterLogin = TwitterLogin(
    apiKey: '123',
    apiSecretKey: '1234',
    redirectURI: 'appname://');
    // Trigger the sign-in flow
    final authResult = await twitterLogin.loginV2();
    print(authResult.toMap());
    // Create a credential from the access token
    final twitterAuthCredential = TwitterAuthProvider.credential(
    accessToken: authResult.authToken!,
    secret: authResult.authTokenSecret!,
    );
    // Once signed in, return the UserCredential
    return await FirebaseAuth.instance
    .signInWithCredential(twitterAuthCredential);
    }
    
  6. 根本没有使用firebase提供的回调(这在README中也提到了,但我太笨了,没有检查)

最新更新