gpt4 book ai didi

ios - 如何使用 iOS 为 AWS API Gateway (Swift) 生成的开发工具包

转载 作者:可可西里 更新时间:2023-11-01 01:39:04 25 4
gpt4 key购买 nike

我使用 AWS API Gateway 创建了一个 API,但每当我尝试访问任何资源时,我都会收到此错误。

Error Domain=com.amazonaws.AWSAPIGatewayErrorDomain Code=1 "(null)" UserInfo={HTTPBody=<CFBasicHash 0x7fd5d87baaf0 [0x102c007b0]>{type = immutable dict, count = 1,
entries =>
0 : message = <CFString 0x7fd5d87bf100 [0x102c007b0]>{contents = "Not able to access resource."}
}
, HTTPHeaderFields=<CFBasicHash 0x7fd5d87bf2a0 [0x102c007b0]>{type = immutable dict, count = 8,
entries =>
0 : X-Cache = <CFString 0x7fd5d87bf030 [0x102c007b0]>{contents = "Error from cloudfront"}
1 : Content-Type = <CFString 0x7fd5d87bd900 [0x102c007b0]>{contents = "application/json"}
3 : x-amzn-RequestId = <CFString 0x7fd5d87baa70 [0x102c007b0]>{contents = "2728fe5f-51b0-11e5-8d25-ada09d3fa091"}
4 : Via = <CFString 0x7fd5d87bcfb0 [0x102c007b0]>{contents = "1.1 87b90692aeeb296771124f5335f08b68.cloudfront.net (CloudFront)"}
6 : Date = <CFString 0x7fd5d87be8d0 [0x102c007b0]>{contents = "Wed, 02 Sep 2015 20:21:11 GMT"}
10 : Content-Length = 43
11 : X-Amz-Cf-Id = <CFString 0x7fd5d87bd0f0 [0x102c007b0]>{contents = "0aL_H-QzchVHBgsYChJ9YwJOs0PKpdFzouXJsDDausqQ9bpunaJmFg=="}
12 : Connection = <CFString 0x7fd5d87be8b0 [0x102c007b0]>{contents = "keep-alive"}
}
}

我的资源需要 api key 但不需要“授权类型”。

这里是我配置客户端的 AppDelegate.swift 片段:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: nil)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
MYREKSMyreksApiClient.registerClientWithConfiguration(configuration, forKey: "avfhh3FNkh4JDGWG8AHsH4ogucFZjmkEUJIn0C44")
return true
}

这就是我从 Controller 调用的方式。

let serviceClient = CLIMyApiClient(forKey: apiKey)
var object = CLICustomObject()
object.param_01 = "Param 01"
object.param_02 = "Param 02"
let result = serviceClient.customObjectPost(contentShare).continueWithBlock{ (task:AWSTask!) -> (AnyObject!) in
if task.error != nil {
print(task.error)
} else {
print("Good!")
}
return nil
}

我为什么会收到这个错误有什么想法吗?

最佳答案

好的,我已经设法找出错误...

我的代码中有一些错误:

  1. 当我注册我的客户端“forKey”时,该键只是一个用于检索我的客户端的字典键。我并没有真正在那里添加我的 API key 。因此,我将其更改为更有意义的 key 。

  2. 要在客户端中实际设置我的 API key ,我必须...好吧,在客户端中设置它:

    let serviceClient = CLIApiClient(forKey: "MoreMeaningfulKey")
    serviceClient.APIKey = "MyActuallyAPIKey"

就是这样!

显然,在 AWS API Gateway、iOS 和 Android 团队中,他们彼此不交谈。这就是你在 Android 上的称呼:

ApiClientFactory factory = new ApiClientFactory().endpoint(END_POINT).apiKey(API_KEY);
MyApiClient client = factory.build(MyApiClient.class);

关于ios - 如何使用 iOS 为 AWS API Gateway (Swift) 生成的开发工具包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32362744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com