Objective c 使用PodioKit将URL写入嵌入字段

Objective c 使用PodioKit将URL写入嵌入字段,objective-c,podio,Objective C,Podio,我希望能找到一些帮助来深入研究Podiokit,Podio的ObjC API。我尝试将链接字段的值设置为URL。我的第一次简单尝试如下所示: NSDictionary *embedAttributes = [NSDictionary dictionaryWithObject: @"http://www.google.com" forKey: @"url"]; PKTEmbed *embed = [[PKTEmbed alloc] initWithDictionary: e

我希望能找到一些帮助来深入研究Podiokit,Podio的ObjC API。我尝试将链接字段的值设置为URL。我的第一次简单尝试如下所示:

NSDictionary *embedAttributes = [NSDictionary dictionaryWithObject: @"http://www.google.com" forKey: @"url"];            
PKTEmbed *embed = [[PKTEmbed alloc] initWithDictionary: embedAttributes];
item[@"linkfield"] = embed;
我找到了一个使用PHP的示例,但没有幸将其转换为Objective-C:

$attributes = array( 'url' => 'http://www.infranet.com' );
$embed = PodioEmbed::create( $attributes );
$attribute['embed']['embed\_id'] = $embed->embed\_id;
$attribute['file']['file\_id'] = $embed->files[0]->file\_id;
$this->orgItem->field('organizationlink')->set\_value($attribute);
也许有人知道如何做对,那就好了:-)

[编辑]PodioKit手册只是说:

PKTEmbed *link = ...;
item[@"link"] = link;
[编辑2]尝试保存项目时出错。日志上写着:

Error: Saving file Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: Ungültige Anforderung (400)" UserInfo=0x600000c7ee80 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x6000008358e0> { URL: https://api.podio.com/item/app/_xxxx_/ } { status code: 400, headers {
"Content-Length" = 263;
"Content-Type" = "application/json; charset=utf-8";
Date = "Sat, 27 Sep 2014 19:16:22 GMT";
Server = nginx;
"X-Podio-Request-Id" = yqyl6yku;
"X-Rate-Limit-Limit" = 250;
"X-Rate-Limit-Remaining" = 248;
} }, NSLocalizedDescription=Request failed: Ungültige Anforderung (400), NSErrorFailingURLKey=https://api.podio.com/item/app/_xxxx_/}
Error:Saving file Error Domain=com.alamofire.Error.serialization.response code=-1011“请求失败:Ungültige Anforderung(400)”UserInfo=0x600000c7ee80{com.alamofire.serialization.response.Error.response={URL:https://api.podio.com/item/app/_xxxx_/ }{状态代码:400,标题{
“内容长度”=263;
“内容类型”=“应用程序/json;字符集=utf-8”;
日期=“2014年9月27日星期六19:16:22 GMT”;
服务器=nginx;
“X-Podio-Request-Id”=yqyl6yku;
“X-费率限制-限制”=250;
“X-利率限制-剩余”=248;
}},NSLocalizedDescription=请求失败:Ungültige Anforderung(400),nserrorfailingurkey=https://api.podio.com/item/app/_xxxx_/}
谢谢,
迈克尔/汉堡

塞巴斯蒂安在这里的波迪奥。您需要首先创建PKTEmbed对象服务器端,然后将其用作item字段的值。因此,您可以使用:

PKTItem *item = ...;
[[PKTEmbed createEmbedForURLString:@"https://www.google.com"] onSuccess:^(PKTEmbed *embed) {
  item[@"link-field"] = embed;
} onError:^(NSError *error) {
  // Handle error
}];
服务器将为您分配一个嵌入ID,并为您生成一个缩略图等。我将考虑添加直接提供URL字符串的功能,因为我同意这很有意义


希望有帮助

嗯。。。你犯了什么错误?您将
项目
定义为什么?这些东西会有帮助的。前面定义了Item:PKTItem*Item=[PKTItem itemForAppWithID:appId];设置其他字段的值没有问题。我认为问题在于,获得一个只包含URL的PKTEmbed的可接受实例…创建PKTEmbed实例后,其嵌入ID为0。哇,我几乎复制/粘贴了您的代码,它工作得非常完美!来自德国/汉堡的问候!现在,我添加了在对象创建时直接使用URL提供
NSString
的功能。像
项[“链接字段”]=@https://www.google.com“
您只需运行
pod update
即可从主分支获取最新更改。希望有帮助!这是一个很好的明显的进步!我认为它在设置链接字段的值时会有很大的帮助,它实际上更直截了当:-)但另一种方法也有效!