Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Get the last question in the DB for this user
- $this->ResetValues();
- $this->SetValue('user_id', $user_id);
- $last_question = current($this->GetAssoc('question_id', 'question_id', 'DESC', 0, 1));
- // Start the API connection
- $connection = new FormspringOAuth(CONSUMER_KEY, CONSUMER_SECRET,
- $myUser->GetValue('oauth_token'), $myUser->GetValue('oauth_token_secret'));
- // Grab new items in the inbox
- $inbox = $connection->get('answered/list/' . $myUser->GetValue('username'), array('since_id' => (int)$last_question));
- $max_id = 0;
- $total_imported = 0;
- do {
- // If we have to get older items
- if ($max_id != 0)
- $inbox = $connection->get('answered/list/' . $myUser->GetValue('username'), array('max_id' => $max_id));
- // Loop through and make sure the questions are in the database
- if (is_array($inbox->response))
- foreach ($inbox->response as $answer){
- if ($answer->id > (int)$last_question){
- // Set all the values for the database
- $this->ResetValues();
- $this->SetValue('question_id', $answer->id);
- $this->SetValue('question', $answer->question);
- $this->SetValue('answer', $answer->answer);
- $this->SetValue('date_asked', date('Y-m-d H:i:s', strtotime($answer->time)));
- $this->SetValue('user_id', $myUser->GetPrimary());
- // Save the new answer
- if (!$this->Save())
- throw new SimplException('Error saving answer to database', 2, 'Error: Saving answer to database: ' . $answer->id);
- // Increment the number of imported items
- $total_imported++;
- }
- // Set the new max id
- $max_id = $answer->id;
- }
- }while ($max_id != 0 && is_array($inbox->response) && count($inbox->response) > 0);
Add Comment
Please, Sign In to add comment