问题描述
我有一个使用GAE Python SDK 1.8.3在本地运行的python webservice。使用Google Cloud Endpoints服务生成器注释API并生成iOS客户端类后,我试图调用使用它的远程过程。
I have a python webservice running locally using GAE Python SDK 1.8.3. After annotating the API and generating iOS client classes using Google Cloud Endpoints Service Generator I'm trying to call a remote procedure using it.
如果我使用API Explorer测试API ,一切正常。
If I test my api using API Explorer, everything works just fine.
当我使用iOS客户端进行呼叫时,该呼叫被web服务接收,但是该请求无法正确解码。这是我第一次使用Endpoints API,所以我不知道什么是错的。
When I call using the iOS client, the call is received by the webservice, however the request cannot be decoded correctly. This is my first time using the Endpoints API so I don't know what is wrong.
似乎发生的事情是,我的请求对象被包装在查询JSON中的资源键中。现在,当我的web服务尝试解码它时,它会产生一条警告,提示无法识别无法识别的字段:资源。而且,由于我的对象被封装在这个键中,所以它被跳过并且不会解码为消息。
What seems to be happening is that my request object is being wrapped in a "resource" key in the query JSON. Now, when my webservice tries to decode it, it yields a warning saying "No variant found for unrecognized field: resource". And, as my object is wrapped inside this key, it is skipped and never decoded to a message.
当使用API Explorer进行调用时,对象不会被包装,所以一切正常。
When the call is made using the API Explorer the object is not wrapped, so everything works.
这就是我在我的web服务中所做的:
This is what I'm doing in my webservice:
@endpoints.method(SearchRequest,
ContactListResponse,
path='search', http_method='post',
name='api.search')
def search(self, request):
user = request.user
number = request.number
这就是我如何从iOS调用它:
This is how I call it from iOS:
GTLMyAPIMessagesSearchRequest * request = [[GTLMyAPIMessagesSearchRequest alloc] init];
request.user = @"+552199881234";
request.number = @"+5521717171";
GTLQueryMyAPI *query = [GTLQueryMyAPI queryForApiSearchWithObject:request];
[service executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLMyAPIMessagesContactListResponse* object,
NSError *error)
{
NSArray* contacts = object.contacts;
}
我在这里做了什么令人难以置信的错误?
Am I doing anything incredibly wrong here?
推荐答案
这不是一个好的解决方案,而是现在的补丁。在进行iOS端点本地主机测试时遇到同样的问题。但是,当我使用已部署的后端时,我删除了这一行,并且一切正常。
This is not a great solution but a patch for now. I have the same problem when doing iOS endpoints localhost testing. However when I use the deployed backend I remove this line and everything is fine.
auth.shouldAuthorizeAllRequests = YES;
仅当我添加上面的行以使用localhost时,才会发生资源密钥包装问题。所以今天早上我没有使用localhost,只是部署版本。让我知道你是否解决了这个问题。 :)显然指向部署的版本并不是首选的测试。
The "resource" key wrapping issue only happens when I add the line above to use localhost. So this morning I'm not using localhost, just the deployed version. Let me know if you fix the issue. :) Obviously pointing to the deployed version is not preferred for testing.
这篇关于Google云端点生成的iOS客户端无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!