无法在Dribbble中创建镜头

时间:2017-10-27 07:03:57

标签: php

我需要你的帮助:

我尝试在Dribbly中创建一个镜头,但收到错误消息。

我按照文档(http://developer.dribbble.com/v1/shots/#create-a-shot)中的描述进行了操作。这是我的代码:

$url = "http://www.rodos-palace.gr/uploads/images/509.jpg"; 
    print_r($drib->create_shot('shottitle', $url)); 



public function create_shot($title, $image, $description = false)
{
    $query = array(
        'title' => $title,
        'image' => $image
    );

    if ($description) {
        $query['description'] = $description;
    }

//   print_r("<br>crearing_shot-> ".__LINE__);

$query['access_token'] = $this->access_token;


return $this->curl_post_shot($this->short_api, $query);

//    return $this->curl_post_shot($this->short_api . "?" . 'access_token=' . $this->access_token, http_build_query($query));
}


public function curl_post_shot($url, $post)
{


    $headers = array("Content-Type: multipart/form-data");

    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_URL => $url,
        CURLOPT_POST => 1,
        CURLOPT_POSTFIELDS => $post,
        CURLOPT_HTTPHEADER => $headers,

        /*,       // stop after 10 redirects
        CURLOPT_SSL_VERIFYPEER => false*/
    ));

    curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, true );
    curl_setopt($curl, CURLINFO_HEADER_OUT, true);

    $information = curl_getinfo($curl);

    if( ($resp = curl_exec($curl)) === false )
    {
        echo 'Curl error: ' . curl_error($curl);
    }
    else
    {
       // echo 'Operation completed without any errors';
    }

    //echo "Check HTTP status code >>>>";
    // Check HTTP status code
    if (!curl_errno($curl)) {
      switch ($information = curl_getinfo($curl, CURLINFO_HTTP_CODE)) {
        case 200:  # OK
          break;
        default:
          { /*echo 'Unexpected HTTP code: ', $http_code, "\n";*/}
      }
    }
    curl_close($curl);

    print_r("<br>crearing_shot-> ".__LINE__);

    echo "<pre>";

    var_dump($information);
    print_r("<br>----------------------------<br>");

    print_r($headers);
    return $resp;
}

这是错误:

  

{&#34; message&#34;:&#34;验证失败。&#34;,&#34;错误&#34;:[       {         &#34;属性&#34;:&#34;图像&#34;,         &#34;消息&#34;:&#34;文件是必需的&#34;       }]}

除此之外,我尝试用图像真实路径和PHP $_FILES来做,结果是一样的。

请帮我解决这个问题。 非常感谢。

1 个答案:

答案 0 :(得分:0)

由于我无法验证,因为我没有上传者帐户,我建议使用cURL文件类上传文件。有多种方法可以解决这个问题,但是既然你使用OOP就应该尝试这个:

public function create_shot($title, $image, $description = false)
{
    $query = array(
        'title' => $title,
        'image' => new CURLFile($image), // $image is the absolute path to the image file
    );

    if ($description) {
        $query['description'] = $description;
    }

    $query['access_token'] = $this->access_token;

    return $this->curl_post_shot($this->short_api, $query);
}

您可以在manual中找到有关文件上传的详细信息。