You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中OAuth1三方认证调用Schoology API失败求助

Schoology API三腿OAuth1认证Flutter实现失败,报错"Bad state: "

我持有Schoology学生账号,已获取该API的consumer token和secret,且在Postman中验证双腿OAuth1认证可正常调用接口。但在Flutter中使用oauth1 Dart包实现三腿OAuth1认证时始终失败,持续收到错误提示Bad state: ,无法按预期打印收件箱消息。

用户点击按钮时会触发以下测试代码(注:生产环境不会硬编码密钥或使用print方法):

void stepOne() {
    final oauth1.Platform platform = oauth1.Platform(
        'https://api.schoology.com/v1/oauth/request_token',
        'https://api.schoology.com/v1/oauth/authorize',
        'https://api.schoology.com/v1/oauth/access_token',
        oauth1.SignatureMethods.hmacSha1
    );
    //define consumer key and secret (in my actual code both are obviously included)
    const String consK = "--CENSORED--";
    const String consS = "--CENSORED--";

    final oauth1.ClientCredentials clientCredentials = oauth1.ClientCredentials(consK, consS);
    final oauth1.Authorization auth = oauth1.Authorization(clientCredentials, platform);

    // request temporary credentials
    auth.requestTemporaryCredentials('oob').then((res) {
      // redirect to authorization page
      print('Open with your browser: ${auth.getResourceOwnerAuthorizationURI(res.credentials.token)}');

      // get verifier (PIN)
      stdout.write('PIN: ');
      String verifier = stdin.readLineSync() ?? '';

      // request token credentials (access tokens)
      return auth.requestTokenCredentials(res.credentials, verifier);
    }).then((res) {
      // you've got token credentials
      // create Client object
      final oauth1.Client client = oauth1.Client(
          platform.signatureMethod,
          clientCredentials,
          res.credentials
      );

      // now you can access protected resources via client
      client.get(Uri.parse('https://api.schoology.com/v1/messages/inbox')).then((res) {
        print('API Response: ${res.body}');
      });

      // You can get optional values from AuthorizationResponse object if needed
      // print('Your screen name is ${res.optionalParameters['screen_name']}');
    }).catchError((error) {
      print('Error during OAuth process: $error');
    });
  }

求有OAuth1或Schoology API使用经验的开发者帮忙排查问题,谢谢!

内容的提问来源于stack exchange,提问作者Ari S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 06:25:08