我在laravel项目中使用的是“ j0k3r / php-imgur-api-client”包。 它的安装似乎很好,很幸运。 然后我编写了一个测试种子脚本(UnitTestSeeder.php)和一个类(ImgurClient.php),如下所示:
<?php
use Illuminate\Database\Seeder;
use App\Libs\Service\ImgurClient;
class UnitTestSeeder extends Seeder{
public function run(){
$username = 'your_imgur_username';
$id = 'Iemhfpo';
//$response = $this->galleryFavorites($username);//run ok
//$response = $this->favorites($username);// run ok
//$response = $this->randomGalleryImages();//run ok
//$response = $this->uploadImage();//run error
//$response = $this->createAlbum();//run error
print_r($response);
}
private function uploadImage(){
$client = new ImgurClient();
$fpath = storage_path('app/public/test.jpg');
$imageData = ['image' => $fpath, 'type' => 'file'];
return $client->upload($imageData);
}
private function createAlbum(){
$client = new ImgurClient();
$album_data = [];
$album_data['title'] = 'Bracelet';
$album_data['description'] = 'Beautiful Bracelet';
$album_data['privacy'] = 'public';
$album_data['layout'] = 'grid';
return $client->createAlbum($album_data);
}
private function randomGalleryImages(){
$client = new ImgurClient();
return $client->randomGalleryImages();
}
private function galleryFavorites($username){
$client = new ImgurClient();
return $client->galleryFavorites($username);
}
private function favorites($username){
$client = new ImgurClient();
return $client->favorites($username);
}
但是很遗憾,如上面的代码注释所示, 一些API调用无法正常工作,而另一些API调用则可以正常工作。
2个调用(createAlbum和uploadImage)引发了这样的异常 Please view my screenshot here 有人遇到过这样的错误吗?谢谢大家!