使用PodioKit将URL写入嵌入字段

时间:2014-09-27 20:22:54

标签: objective-c podio

我希望能找到一些帮助,让我们深入了解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_/}

谢谢, 迈克尔/汉堡

1 个答案:

答案 0 :(得分:1)

塞巴斯蒂安在Podio这里。您需要首先创建PKTEmbed对象服务器端,然后将其用作项字段的值。所以你会使用:

PKTItem *item = ...;
[[PKTEmbed createEmbedForURLString:@"https://www.google.com"] onSuccess:^(PKTEmbed *embed) {
  item[@"link-field"] = embed;
} onError:^(NSError *error) {
  // Handle error
}];

服务器将为您分配一个embedID并为您生成缩略图等。我将考虑添加直接提供URL字符串的功能,因为我同意这很有道理。

希望有所帮助!