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 header 的原因是 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"
}

您不必 post 将字段标记为 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 开发人员,但您可以在此处查看如何 post 形成数据的示例 -