Flickr API-照片集添加照片

时间:2018-11-26 19:50:22

标签: flickr

我在Flickr API上遇到问题-照片集添加照片(https://www.flickr.com/services/api/flickr.photosets.addPhoto.html

这是我的代码:

上传(工作正常)

    protected function doUpload()
{
    $params = $this->getParameters(array(
        'title'          => basename($this->file),
        'description'    => self::POWERED_BY,
        'tags'           => self::POWERED_BY,
        'is_public'      => '0',
        'is_friend'      => '0',
        'is_family'      => '0',
        'content_type'   => 1, // 1: photo, 2:screenshot
        'safety_level'   => '',
        'hidden'         => '',
        'oauth_token'    => $this->getAccessToken(),
    ));

    list($url, $params) = $this->prepareOAuthRequestData(self::UPLOAD_ENDPOINT, 'POST', $params);
    $params['photo'] = '@' . $this->file;

    $this->resetHttpClient();
    $this->client->setParameters($params);
    $this->client->setSubmitMultipart();
    $this->client->execute($url);
    $text = $this->client->getResponseText();

    if (!$photoId = $this->getMatch('#<photoid>([\d]+)</photoid>#i', $text)) {
        parse_str($text, $result);
        if (isset($result['oauth_problem'])) {
            $this->throwException('UPLOAD_PROBLEM: "%s"', $result['oauth_problem']);
        } else {
            $error = $this->getMatch('#code="(.+?)"#', $text);
            $msg =   $this->getMatch('#msg="(.+?)"#', $text);
            $this->throwException('UPLOAD_PROBLEM: "%s" (%d)', $msg, $error);
        }
    }
    $this->call('flickr.photosets.addPhoto', array('photoset_id' => '333333', 'photo_id' => $photoId));
    $result = $this->call('flickr.photos.getInfo', array('photo_id' => $photoId));


    return $this->getPhotoUrl($result['photo']);


}

给Func打电话(flickr.photos.getInfo运行良好)

protected function call($method, array $params = array())
{
    $params += $this->getParameters($params + array(
        'method'         => $method,
        'oauth_token'    => $this->getAccessToken(),
        'format'         => 'json',
        'nojsoncallback' => '1'
    ));
    list($url, $params) = $this->prepareOAuthRequestData(self::API_ENDPOINT, 'GET', $params);

    $this->resetHttpClient();
    $this->client->execute($url);

    if (false === $result = json_decode($this->client->getResponseText(), true)) {
        parse_str($this->client->getResponseText(), $result);
        if (isset($result['oauth_problem'])) {
            $this->throwException('API_PROBLEM: "%s"', $result['oauth_problem']);
        }
    }
    if ($result['stat'] == 'fail') {
        $this->throwException('API_PROBLEM: "%s" fail. MESSAGE: "%s", CODE: "%s"',
            $method, $result['message'], $result['code']
        );
    }

    return $result;
}

为什么调用flickr.photos.getInfo可以正常工作,而flickr.photosets.addPhoto却不能。

我将GET更改为POST也不起作用。

我不知道。请帮助我。

0 个答案:

没有答案