Changeset 996346
- Timestamp:
- 09/24/2014 09:46:54 PM (12 years ago)
- File:
-
- 1 edited
-
g-crossposting/trunk/g-crossposting.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
g-crossposting/trunk/g-crossposting.php
r995586 r996346 217 217 function g_crossposting_api_activities_list($p_gplusid, $p_apikey, $p_maxactivities, $p_pagetoken) { 218 218 // get list of latest p_maxactivities activities 219 $ch = curl_init("https://www.googleapis.com/plus/v1/people/{$p_gplusid}/activities/public?alt=json&maxResults={$p_maxactivities}&key={$p_apikey}&pageToken={$p_pagetoken}"); 219 $query = "https://www.googleapis.com/plus/v1/people/{$p_gplusid}/activities/public?alt=json&key={$p_apikey}"; 220 221 if (isset($p_maxactivities)) { 222 $query = $query."&maxResults={$p_maxactivities}"; 223 } 224 225 if (isset($p_pagetoken)) { 226 $query = $query."&pageToken={$p_pagetoken}"; 227 } 228 229 $ch = curl_init($query); 220 230 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 221 231 $activities = curl_exec($ch); 222 232 curl_close($ch); 233 223 234 $activities = json_decode($activities); 224 235 … … 241 252 // load options 242 253 $options = g_crossposting_get_settings(); 243 $last_activity_id = get_option('g_crossposting_last_activity_id', null);244 254 245 255 // get activities from Google+ … … 250 260 } 251 261 252 // go through activities to see if we got some not posted yet 253 // stop as soon as we found the last posted one 254 $new_activities = array(); 255 foreach ($activities->items as $activity) { 256 if ($last_activity_id == null || $activity->id != $last_activity_id) { 257 $new_activities[] = $activity; 258 } else { 259 // found an activity already imported 260 // abort, because the list is sorted by time with newest first 261 break; 262 } 263 } 264 265 if (count($new_activities) > 0) { 266 return $new_activities; 262 if (isset($activities->items) && count($activities->items) > 0) { 263 return $activities->items; 267 264 } else { 268 265 return null; … … 279 276 $posts_updated = 0; 280 277 foreach ($activities as $activity) { 281 // store ID of latest activity so that we know what was posted already282 if ($latest_activity_id == null) {283 $latest_activity_id = $activity->id;284 update_option('g_crossposting_last_activity_id' , $latest_activity_id);285 }286 287 278 // no activity ID or one of being null must be wrong 288 if (! isset($activity->id) || $activity->id == null) {279 if (! isset($activity->id)) { 289 280 continue; 290 281 } … … 548 539 { 549 540 $activities = g_crossposting_api_activities_list($options['gplusid'], 550 $options['apikey'], $options['maxactivities'], $nextPageToken);541 $options['apikey'], 100, $nextPageToken); 551 542 if ($activities == null) { 552 543 return null; 553 544 } 554 545 555 $nextPageToken = $activities->nextPageToken; 556 foreach ($activities->items as $activity) 557 { 558 $all_activities[] = $activity; 559 } 546 if (isset($activities->nextPageToken)) { 547 $nextPageToken = $activities->nextPageToken; 548 } else { 549 $nextPageToken = null; 550 } 551 552 $all_activities = array_merge($all_activities, $activities->items); 560 553 } 561 554 while($nextPageToken != null);
Note: See TracChangeset
for help on using the changeset viewer.