@ -25,38 +25,42 @@ class Ins24Service
try {
$userList = file ( " /Users/shixuesen/OneDrive/Pictures/instagram/user.txt " );
$userList = array_slice ( $userList , 1 );
$userList = array_slice ( $userList , 27 , 1 );
// $userList = ['1992.ai_'];
// print_r($userList);exit;
print_r ( $userList ); exit ;
// print_r($userList);
foreach ( $userList as $userName ) {
usleep ( random_int ( 10 , 1000 ) * 100000 );
$sleepTime = random_int ( 10 , 1000 ) * 10000 ;
echo " currentTime: " . date ( " y-m-d H:i:s " ) . " sleep: " . $sleepTime ;
usleep ( $sleepTime );
$trueName = trim ( $userName );
$thisUserImageDir = $baseImageDir . $trueName . " / " ;
$maxId = " 2034758748461248535_13049295449 " ;
$pageNo = 75 ;
$maxId = " " ;
$pageNo = 1 ;
$pageNo = 0 ;
$flag = true ;
for (; ;) {
try {
$data = $this -> queryImage ( $trueName , $pageNo , $maxId );
$maxId = $data [ " maxId " ];
$pageNo ++ ;
if ( count ( $data [ " resourceList " ]) == 0 ) {
break ;
}
if ( $flag && $data [ " maxId "] != " 2263028000987470356_13049295449 ") {
echo " maxId not matched! \n ";
$flag = false ;
continue ;
}
// if ($flag && $data["maxId"] != "2263028000987470356_13049295449") {
// echo "maxId not matched! \n";
// $flag = false;
// continue;
// }
foreach ( $data [ " resourceList " ] as $resource ) {
$res = $this -> downloadFile ( $resource [ " mediaURL " ], 0 , $thisUserImageDir );
usleep ( random_int ( 10 , 1000 ) * 100000 );
if ( $res == 0 ) {
break ;
break 2 ;
}
}
$maxId = $data [ " maxId " ];
$pageNo ++ ;
} catch ( \Exception $e ) {
Log :: error ( " ins get user id for name error: " . $e -> getMessage () . " username is " . $userName );
}
@ -80,7 +84,9 @@ class Ins24Service
// print_r($userList);exit;
// print_r($userList);
foreach ( $userList as $userName ) {
usleep ( random_int ( 10 , 1000 ) * 100000 );
$sleepTime = random_int ( 10 , 1000 ) * 10000 ;
echo " currentTime: " . date ( " y-m-d H:i:s " ) . " sleep: " . $sleepTime ;
// usleep(random_int(10, 1000) * 100000);
$trueName = trim ( $userName );
$thisUserImageDir = $baseImageDir . $trueName . " / " ;
@ -89,6 +95,8 @@ class Ins24Service
for (; ;) {
try {
$data = $this -> queryVideo ( $trueName , $pageNo , $maxId );
$maxId = $data [ " maxId " ];
$pageNo ++ ;
if ( count ( $data [ " resourceList " ]) == 0 ) {
break ;
}
@ -121,7 +129,7 @@ class Ins24Service
CURLOPT_RETURNTRANSFER => true ,
CURLOPT_ENCODING => " " ,
CURLOPT_MAXREDIRS => 10 ,
CURLOPT_TIMEOUT => 0 ,
CURLOPT_TIMEOUT => 20 0,
CURLOPT_FOLLOWLOCATION => true ,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1 ,
CURLOPT_CUSTOMREQUEST => " POST " ,
@ -149,12 +157,12 @@ class Ins24Service
if ( curl_exec ( $curl ) === false )
{
echo 'Curl error: ' . curl_error ( $curl );
} else {
echo $response ;
// exit;
}
curl_close ( $curl );
$formatResponse = json_decode ( $response , true );
if ( $formatResponse [ " code " ] == 200 ) {
echo " userName: $userName , maxId: " . $formatResponse [ " data " ][ " maxId " ] . " pageNo: " . $pageNo . " count: " . count ( $formatResponse [ " data " ][ " resourceList " ]) . " \n " ;
return $formatResponse [ " data " ];
} else {
echo $response ;
@ -174,7 +182,7 @@ class Ins24Service
CURLOPT_RETURNTRANSFER => true ,
CURLOPT_ENCODING => " " ,
CURLOPT_MAXREDIRS => 10 ,
CURLOPT_TIMEOUT => 0 ,
CURLOPT_TIMEOUT => 20 0,
CURLOPT_FOLLOWLOCATION => true ,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1 ,
CURLOPT_CUSTOMREQUEST => " POST " ,
@ -202,12 +210,12 @@ class Ins24Service
if ( curl_exec ( $curl ) === false )
{
echo 'Curl error: ' . curl_error ( $curl );
} else {
echo $response ;
// exit;
}
curl_close ( $curl );
$formatResponse = json_decode ( $response , true );
if ( $formatResponse [ " code " ] == 200 ) {
echo " userName: $userName , maxId: " . $formatResponse [ " data " ][ " maxId " ] . " pageNo: " . $pageNo . " count: " . count ( $formatResponse [ " data " ][ " resourceList " ]) . " \n " ;
return $formatResponse [ " data " ];
} else {
echo $response ;
@ -235,7 +243,7 @@ class Ins24Service
// $flag = 1;
// }
if ( file_exists ( $filePrefix . $filename ) || file_exists ( $filePrefix . $filename . " .back " )) {
echo " \n file exists " . $filePrefix . $filename ;
echo " \n file exists " . $filePrefix . $filename . " \n " ;
return 0 ;
}
try {