["/Users/shixuesen/Documents/sync/image/芝芝Booty", 1661956020], // "/Users/shixuesen/Documents/local/xg/wyc" => ["/Users/shixuesen/Documents/sync/image/王雨纯", 1661956020], // "/Users/shixuesen/Documents/local/xg/ycc" => ["/Users/shixuesen/Documents/sync/image/杨晨晨", 1661956020], // "/Users/shixuesen/Documents/local/xg/hlr" => ["/Users/shixuesen/Documents/sync/image/黄乐然", 1661956020], // "/Users/shixuesen/Documents/local/xg/jrq" => ["/Users/shixuesen/Documents/sync/image/姜仁卿", 1661956020], // "/Users/shixuesen/Documents/local/xg/azu" => ["/Users/shixuesen/Documents/sync/image/是阿朱啊", 1661956020], // "/Users/shixuesen/Documents/local/xg/xq" => ["/Users/shixuesen/Documents/sync/image/小琪", 1661956020], // "/Users/shixuesen/Documents/local/xg/小雪" => ["/Users/shixuesen/Documents/sync/image/小雪", 1661956020], "/Users/shixuesen/OneDrive/Pictures/instagram/Likes_new" => ["/Users/shixuesen/Documents/sync/image/instagram/Likes", 1659621180], "/Users/shixuesen/OneDrive/Pictures/instagram/boram__jj" => ["/Users/shixuesen/Documents/sync/image/instagram/boram__jj", 1659621180], "/Users/shixuesen/OneDrive/Pictures/instagram/cho_hyunyoung" => ["/Users/shixuesen/Documents/sync/image/instagram/cho_hyunyoung", 1659621180], "/Users/shixuesen/OneDrive/Pictures/instagram/cxxsomi" => ["/Users/shixuesen/Documents/sync/image/instagram/cxxsomi", 1659621180], "/Users/shixuesen/OneDrive/Pictures/instagram/inkyung97" => ["/Users/shixuesen/Documents/sync/image/instagram/inkyung97", 1659621180], "/Users/shixuesen/OneDrive/Pictures/instagram/chen_01_24" => ["/Users/shixuesen/Documents/sync/image/instagram/chen_01_24", 1659621180], "/Users/shixuesen/OneDrive/Pictures/instagram/mobe_carrie0223" => ["/Users/shixuesen/Documents/sync/image/instagram/mobe_carrie0223", 1659621180], "/Users/shixuesen/OneDrive/Pictures/instagram/na0912mi" => ["/Users/shixuesen/Documents/sync/image/instagram/na0912mi", 1659621180], "/Users/shixuesen/OneDrive/Pictures/instagram/sejinming" => ["/Users/shixuesen/Documents/sync/image/instagram/sejinming", 1659621180] ]; private $compressMapping = [ "##1##" => "\/Users\/shixuesen\/Documents\/local\/xg\/", "##2##" => "\/Users\/shixuesen\/Documents\/sync\/image\/", "##3##" => "\/Users\/shixuesen\/OneDrive\/Pictures\/instagram\/" ]; public function insertMappings() { $value = json_encode($this->map); $replacedValue = str_replace(array_values($this->compressMapping), array_keys($this->compressMapping), $value); echo $replacedValue; echo "\n"; // $replacedValue = str_replace(array_keys($this->compressMapping), array_values($this->compressMapping), $replacedValue); // dump(json_decode($replacedValue));exit; $commonSettings = new CommonSettingService(); $commonSettings->addSettings(SettingKeys::SYNC_DIR_MAPPING, $replacedValue); } public function syncImageFiles() { $commonSettings = new CommonSettingService(); $item = $commonSettings->queryByKey(SettingKeys::SYNC_DIR_MAPPING)->first(); $trueMappings = str_replace(array_keys($this->compressMapping), array_values($this->compressMapping), $item->value); // dump(array_slice(json_decode($trueMappings, true), 8));exit; $service = new FileService(); $service->copySelectedFilesToMappedDirectory(array_slice(json_decode($trueMappings, true), 8)); } 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]); } }