You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

71 lines
2.5 KiB

<?php
namespace App\Http\Controllers;
use Google\ApiCore\ApiException;
use Google\Photos\Library\V1\PhotosLibraryClient;
use Illuminate\Http\Request;
class GooglePhotoController extends Controller {
public function connect(Request $request)
{
connectWithGooglePhotos($request,
['https://www.googleapis.com/auth/photoslibrary'],
config('app.albums_authentication_redirect_url')
);
}
public function index()
{
$credentials = session("credentials");
if ($credentials == null || $credentials == "") {
return view("albums/connect");
}
$photosLibraryClient = new PhotosLibraryClient(['credentials' => $credentials]);
try {
// $options['proxy'] = 'http://127.0.0.1:1087';
// $pagedResponse = $photosLibraryClient->listAlbums();
// $options['pageSize'] = 5;
$pagedResponse = $photosLibraryClient->listMediaItems();
// echo 111;
// var_dump($pagedResponse->iterateAllElements());exit;
$iterator = $pagedResponse->iterateAllElements();
$albums = [];
$yccImages = [];
while (true) {
for ($i = 0; $i < 100; $i++) {
$album = $iterator->current();
if (strstr($album->getFilename(), "ycc")) {
$yccImages[] = $album->getId();
}
$iterator->next();
}
if (count($yccImages) > 1) {
$photosLibraryClient->batchAddMediaItemsToAlbum("AN5jk26M4hJ-wxLPKSzIDyjruMMkWjlDlVkgNaWWk3d3c7TGhm1vKU-YM0JhfgK5CfcfneoIx_8E", $yccImages);
echo "add " . count($yccImages) . " images to ycc\n";
$yccImages = [];
}
break;
}
//// echo $album->getProductUrl();
// $albums[] = $album;
// $iterator->next();
// }
// exit;
// By using iterateAllElements, pagination is handled for us.
return view("albums.index", ['albums' => $pagedResponse->iterateAllElements()]);
// echo $templates->render(
// 'albums::index',
// ['albums' => $pagedResponse->iterateAllElements()]);
// echo $templates->render(
// 'albums::index',
// ['mediaItems' => $albums]
// );
// );
} catch (ApiException $e) {
// echo $templates->render('error', ['exception' => $e]);
view("error");
}
}
}