繁体   English   中英

Marketo REST API资产令牌是否有效?

[英]Does the Marketo REST API asset Token work?

我正在关注文档的这一部分: http//developers.marketo.com/rest-api/assets/tokens/我总是得到以下错误:字段不能为空。

有没有人让它工作?

public function create_token($folder_id,$name,$content,$folder_type = 'Program')
{
    $folder_id = intval($folder_id);
    $endpoint = 'rest/asset/v1/folder/'.$folder_id.'/tokens';
    $body = new stdClass();
    $body->folderType = $folder_type;
    $body->name = $name;
    $body->type = 'rich text';
    $body->value = $content;
    $body_encoded = json_encode($body);

    echo $url = $this->url . $endpoint . ".json?access_token=" . self::$token;

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: x-www-form-urlencoded'));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $body_encoded);
    $response = curl_exec($ch);
    curl_close($ch);
    return json_decode($response);
}

Content-Type标题的原因是Marketo的建议: https ://www.screencast.com/t/CL5ZtPo1o

这是我不断得到的要求的答案:

object(stdClass)#1934 (4) {


["success"]=>
  bool(false)
  ["warnings"]=>
  array(0) {
  }
  ["errors"]=>
  array(4) {
    [0]=>
    object(stdClass)#1935 (2) {
      ["message"]=>
      string(20) "name cannot be null."
      ["code"]=>
      string(3) "701"
    }
    [1]=>
    object(stdClass)#1936 (2) {
      ["message"]=>
      string(20) "type cannot be null."
      ["code"]=>
      string(3) "701"
    }
    [2]=>
    object(stdClass)#1937 (2) {
      ["message"]=>
      string(101) "Token type is either null, blank or invalid. Please refer to the documentation for valid token types."
      ["code"]=>
      string(3) "701"
    }
    [3]=>
    object(stdClass)#1938 (2) {
      ["message"]=>
      string(21) "value cannot be null."
      ["code"]=>
      string(3) "701"
    }
  }
  ["requestId"]=>
  string(16) "11d1#15b49284636"
}

您不必将标记字段作为JSON对象发布: json_encode($body)
字段作为请求参数或常规表单传递

这个请求适用于我:

POST https://123-FOO-456.mktorest.com/rest/asset/v1/folder/1039/tokens.json?value=TestTokenValue&folderType=Program&name=TestToken&type=text

在这种情况下,您也不必指定内容类型Content-Type: x-www-form-urlencoded

我不是PHP dev,但你可以在这里看一下如何发布表单数据的例子 - PHP + curl,HTTP POST示例代码?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM