/** * @param string $file file * @param string $title title * @param string $description description * @param string|array $tags tags * @param boolean $isPublic isPublic * @param boolean $isFriend isFriend * @param boolean $isFamily isFamily * * @return string the photo id */ public function upload($file, $title = null, $description = null, $tags = null, $isPublic = null, $isFriend = null, $isFamily = null) { $uploadReturn = $this->flickerApiFactory->upload($file, $title, $description, $tags, $isPublic, $isFriend, $isFamily); if ($uploadReturn['stat']->__toString() === 'ok') { return $uploadReturn->photoid->__toString(); } else { if ($uploadReturn['stat']->__toString() === 'fail') { throw new FlickrException($uploadReturn->err['msg']->__toString(), $uploadReturn->err['code']->__toString()); } else { throw new FlickrException('Unknown exception'); } } }
/** * 写真をFlickrにアップロード * @param $picture * @param null $title * @param null $description * @param null $tags * @return Flickr * @throws FlickrFailedException */ public function uploadFlickr($picture, $title = null, $description = null, $tags = null) { $metadata = new Metadata(config('const.flickr.apikey'), config('const.flickr.secret')); $metadata->setOauthAccess(config('const.flickr.oauth_token'), config('const.flickr.oauth_token_secret')); $factory = new ApiFactory($metadata, new GuzzleAdapter()); $upload = $factory->upload($picture, $title, $description, $tags, true); if ((string) $upload->attributes()->stat === 'fail') { $errAttr = $upload->err->attributes(); throw new FlickrFailedException((string) $errAttr->msg, (int) $errAttr->code); } $getInfo = $factory->call('flickr.photos.getInfo', array('photo_id' => (string) $upload->photoid)); $photoAttr = $getInfo->photo->attributes(); $flickr = new Flickr(); foreach (['id', 'server', 'farm', 'secret'] as $name) { $flickr->{'flickr_' . $name} = (string) $photoAttr->{$name}; } $flickr->save(); return $flickr; }