"/Users/shixuesen/Documents/sync/image/芝芝Booty", "/Volumes/intel660p/image/xg/wyc" => "/Users/shixuesen/Documents/sync/image/王雨纯", "/Volumes/intel660p/image/xg/ycc" => "/Users/shixuesen/Documents/sync/image/杨晨晨", "/Volumes/intel660p/image/xg/hlr" => "/Users/shixuesen/Documents/sync/image/黄乐然", "/Users/shixuesen/OneDrive/Pictures/instagram/Likes_new" => "/Users/shixuesen/Documents/sync/image/instagram/Likes", "/Users/shixuesen/OneDrive/Pictures/instagram/boram__jj" => "/Users/shixuesen/Documents/sync/image/instagram/boram__jj", "/Users/shixuesen/OneDrive/Pictures/instagram/cho_hyunyoung" => "/Users/shixuesen/Documents/sync/image/instagram/cho_hyunyoung", "/Users/shixuesen/OneDrive/Pictures/instagram/cxxsomi" => "/Users/shixuesen/Documents/sync/image/instagram/cxxsomi", "/Users/shixuesen/OneDrive/Pictures/instagram/inkyung97" => "/Users/shixuesen/Documents/sync/image/instagram/inkyung97", ]; public function syncImageFiles() { $service = new FileService(); $service->copySelectedFilesToMappedDirectory($this->map); } public function syncDBToRedis() { $list = GooglePhoto::paginate(100); do { foreach ($list as $item) { Redis::connection()->sadd("google_photo", $item["photo_id"]); } $list = GooglePhoto::paginate(100, ["*"],"", $list->currentPage() + 1); } while($list->isNotEmpty()); } public function loadSynchronizedPhotoFromGooglePhoto($credentials,PhotosLibraryClient $photosLibraryClient) { $options["pageSize"] = 100; if (Redis::connection()->get("google_photo_token") != null) { $options["pageToken"] = Redis::connection()->get("google_photo_token"); } // $options["pageToken"] = "CkgKQnR5cGUuZ29vZ2xlYXBpcy5jb20vZ29vZ2xlLnBob3Rvcy5saWJyYXJ5LnYxLkxpc3RNZWRpYUl0ZW1zUmVxdWVzdBICCGQSogFBSF91UTQyZWo2TWdQb3cyZDVOOHdubldId0JwakJ0cUJwbHk4akV3Qm8tZ2xvTWpuWlE3M1kzYWJhOFpBeUluSmdaODdnbDhHdXBtYVpuZkRiNnVLY085Qmd4Q3V3bXdhS2ZDTWpKUDhEMndVSG16LXpHdzgtMFpUUzNpY2w4TnZSWklodWRHeXM0RUF1aDE4OGw0djhTTHppUUpQOFV6REEaG3FFZDZPNjc0UlBjbnhNZkoyUUowNG5qQXpxYw"; $pagedResponse = $photosLibraryClient->listMediaItems($options); $page = $pagedResponse->getPage(); do { $num = $page->getPageElementCount(); $iterator = $page->getIterator(); for ($i = 0; $i < $num; $i++) { $photo = $iterator->current(); if (Redis::connection()->sismember("google_photo", $photo->getId())) { $iterator->next(); continue; } Log::info("file not in db " . $photo->getFilename()); GooglePhoto::firstOrCreate(["photo_id" => $photo->getId()], ["photo_id" => $photo->getId(), "filename" => $photo->getFilename(), "product_url" => $photo->getProductUrl(), "creation_time" => date("Y-m-d H:i:s", $photo->getMediaMetadata()->getCreationTime()->getSeconds())] ); Redis::connection()->sadd("google_photo", $photo->getId()); $iterator->next(); } $nextToken = $page->getNextPageToken(); Redis::connection()->set("google_photo_token", $nextToken); Log::info("page token " . $nextToken); } while ($page->hasNextPage() && $page = $page->getNextPage(100)); } public function getAuthToken($code, array $scopes, $redirectURI) { $clientSecretJson = json_decode( file_get_contents('client_secret_1000190146810-j9mohjt8m4m8j8sj6hupl1bghp6o1pdn.apps.googleusercontent.com.json'), true )['web']; // dump($clientSecretJson);exit; $clientId = $clientSecretJson['client_id']; $clientSecret = $clientSecretJson['client_secret']; $oauth2 = new OAuth2([ 'clientId' => $clientId, 'clientSecret' => $clientSecret, 'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth', // Where to return the user to if they accept your request to access their account. // You must authorize this URI in the Google API Console. 'redirectUri' => $redirectURI, 'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token', 'scope' => $scopes, 'expiry' => 7200 ]); $oauth2->setCode($code); $authToken = $oauth2->fetchAuthToken(); $refreshToken = $authToken['access_token']; // The UserRefreshCredentials will use the refresh token to 'refresh' the credentials when // they expire. $credentials = new UserRefreshCredentials( $scopes, [ 'client_id' => $clientId, 'client_secret' => $clientSecret, 'refresh_token' => $refreshToken ] ); session(['credentials' => $credentials]); } }