Guest User

Untitled

a guest
Jul 18th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. // Get the last question in the DB for this user
  2. $this->ResetValues();
  3. $this->SetValue('user_id', $user_id);
  4. $last_question = current($this->GetAssoc('question_id', 'question_id', 'DESC', 0, 1));
  5.  
  6. // Start the API connection
  7. $connection = new FormspringOAuth(CONSUMER_KEY, CONSUMER_SECRET,
  8. $myUser->GetValue('oauth_token'), $myUser->GetValue('oauth_token_secret'));
  9.  
  10. // Grab new items in the inbox
  11. $inbox = $connection->get('answered/list/' . $myUser->GetValue('username'), array('since_id' => (int)$last_question));
  12. $max_id = 0;
  13. $total_imported = 0;
  14.  
  15. do {
  16. // If we have to get older items
  17. if ($max_id != 0)
  18. $inbox = $connection->get('answered/list/' . $myUser->GetValue('username'), array('max_id' => $max_id));
  19.  
  20. // Loop through and make sure the questions are in the database
  21. if (is_array($inbox->response))
  22. foreach ($inbox->response as $answer){
  23. if ($answer->id > (int)$last_question){
  24. // Set all the values for the database
  25. $this->ResetValues();
  26. $this->SetValue('question_id', $answer->id);
  27. $this->SetValue('question', $answer->question);
  28. $this->SetValue('answer', $answer->answer);
  29. $this->SetValue('date_asked', date('Y-m-d H:i:s', strtotime($answer->time)));
  30. $this->SetValue('user_id', $myUser->GetPrimary());
  31.  
  32. // Save the new answer
  33. if (!$this->Save())
  34. throw new SimplException('Error saving answer to database', 2, 'Error: Saving answer to database: ' . $answer->id);
  35.  
  36. // Increment the number of imported items
  37. $total_imported++;
  38. }
  39. // Set the new max id
  40. $max_id = $answer->id;
  41. }
  42. }while ($max_id != 0 && is_array($inbox->response) && count($inbox->response) > 0);
Add Comment
Please, Sign In to add comment