Skip to content

Commit 6058b71

Browse files
committed
Fixed login return value and improved finding friends
1 parent 68c01a6 commit 6058b71

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/snapchat.php

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public function login($username, $password) {
112112

113113
$this->cache = new SnapchatCache();
114114
$this->cache->set('updates', $result);
115+
116+
return $result;
115117
}
116118
else {
117119
return FALSE;
@@ -367,33 +369,36 @@ function getFriendStories($force = FALSE) {
367369
* An array of user objects or FALSE on failure.
368370
*/
369371
public function findFriends($numbers, $country = 'US') {
370-
$numbers = array_flip($numbers);
372+
$batches = array_chunk(array_flip($numbers), 30, TRUE);
371373

372374
// Make sure we're logged in and have a valid access token.
373375
if (!$this->auth_token || !$this->username) {
374376
return FALSE;
375377
}
376378

377-
$timestamp = parent::timestamp();
378-
$result = parent::post(
379-
'/find_friends',
380-
array(
381-
'countryCode' => $country,
382-
'numbers' => json_encode($numbers),
383-
'timestamp' => $timestamp,
384-
'username' => $this->username,
385-
),
386-
array(
387-
$this->auth_token,
388-
$timestamp,
389-
)
390-
);
379+
$results = array();
380+
foreach ($batches as $batch) {
381+
$timestamp = parent::timestamp();
382+
$result = parent::post(
383+
'/find_friends',
384+
array(
385+
'countryCode' => $country,
386+
'numbers' => json_encode($batch),
387+
'timestamp' => $timestamp,
388+
'username' => $this->username,
389+
),
390+
array(
391+
$this->auth_token,
392+
$timestamp,
393+
)
394+
);
391395

392-
if (isset($result->results)) {
393-
return $result->results;
396+
if (isset($result->results)) {
397+
$results = $results + $result->results;
398+
}
394399
}
395400

396-
return $result;
401+
return $results;
397402
}
398403

399404
/**

0 commit comments

Comments
 (0)