InstagramScraper\Model\Account::fromSearchPage PHP Method

fromSearchPage() public static method

public static fromSearchPage ( $userArray )
    public static function fromSearchPage($userArray)
    {
        $instance = new self();
        $instance->username = $userArray['username'];
        $instance->profilePicUrl = $userArray['profile_pic_url'];
        $instance->id = $userArray['pk'];
        $instance->fullName = $userArray['full_name'];
        $instance->isPrivate = $userArray['is_private'];
        $instance->isVerified = $userArray['is_verified'];
        $instance->followedByCount = $userArray['follower_count'];
        return $instance;
    }

Usage Example

Ejemplo n.º 1
0
 public static function searchAccountsByUsername($username)
 {
     $response = Request::get(Endpoints::getGeneralSearchJsonLink($username));
     if ($response->code === 404) {
         throw new InstagramNotFoundException('Account with given username does not exist.');
     }
     if ($response->code !== 200) {
         throw new InstagramException('Response code is ' . $response->code . '. Body: ' . $response->body . ' Something went wrong. Please report issue.');
     }
     $jsonResponse = json_decode($response->raw_body, true);
     if (!isset($jsonResponse['status']) || $jsonResponse['status'] != 'ok') {
         throw new InstagramException('Response code is not equal 200. Something went wrong. Please report issue.');
     }
     if (!isset($jsonResponse['users']) || count($jsonResponse['users']) == 0) {
         return [];
     }
     $accounts = [];
     foreach ($jsonResponse['users'] as $jsonAccount) {
         $accounts[] = Account::fromSearchPage($jsonAccount['user']);
     }
     return $accounts;
 }