我如何解决此DetailsApiRequestError(状态:404,消息:无错误详细信息。HTTP状态为:404。)

时间:2020-07-17 13:29:48

标签: flutter dart google-api

任何人都知道我在做什么错,我不断收到此错误

DetailedApiRequestError(status: 404, message: No error details. HTTP status was: 404.)

这是我的代码。


final _credentials = new ServiceAccountCredentials.fromJson(r'''
  {
    "private_key_id": "4XXXXXxXXXXXXXXXXXXXXXXXXXXXXXXXXXXx",
    "private_key": ".....==\n-----END PRIVATE KEY-----\n",
    "client_email": "xxxxxxx@----.com",
    "client_id": "11XXXXXXXXXXXXXX4",
    "type": "service_account"
  }
  ''');

clientViaServiceAccount(_credentials, _SCOPES).then((http_client) {
      var pubSubClient = new PubsubApi(http_client);

      var messages = {
        'messages': [
          {
            'data': base64Encode(utf8.encode('{"foo": "bar"}')),
          },
        ]
      };



      pubSubClient.projects.topics
          .publish(new PublishRequest.fromJson(messages), "your-topic")
          .then((publishResponse) {
        debugPrint(publishResponse.toString());
      }).catchError((e,m){
        debugPrint(e.toString());
      });
    });

我在initState()中有一个带状态代码的小部件,当我运行它时,出现上面的错误。当我检查我的Google Cloud时,什么都没有发布。任何可以快速帮助我的人。

1 个答案:

答案 0 :(得分:0)

这是一个解决方案,请更改此内容:


pubSubClient.projects.topics
          .publish(new PublishRequest.fromJson(messages), "your-topic")
          .then((publishResponse) {
        debugPrint(publishResponse.toString());
      }).catchError((e,m){
        print(m.toString());
        debugPrint(e.toString());
      });

对此:


    pubSubClient.projects.topics
          .publish(new PublishRequest.fromJson(messages), "projects/projectIDXX/topics/yourTopic")
          .then((publishResponse) {
        debugPrint(publishResponse.toString());
      }).catchError((e,m){
        print(m.toString());
        debugPrint(e.toString());
      });

问题出在主题上。