$etag = $ask_response['headers']['ETag']; $question_identifier = end(explode('/', $ask_response['@attributes']['href'])); $answer_response = answers_api::answer($question_identifier, "OMG great question! No clue about that though.", $etag); print_r($answer_response); // standard search example using default options $search_response = answers_api::search('When does the bacon narwhal?'); print_r($search_response); // paged and filtered search example $page = 2; $limit = 5; $filters = array( 'filters' => 'answered', 'corpus' => 'wiki' ); $paged_response = answers_api::search('Why is the sky blue?', $filters, $page, $limit); print_r($paged_response); // categorize example $cat_response = answers_api::categorize('The bacon narwhals at midnight'); print_r($cat_response); ?>
/** * Authenticate against the Answers API with Facebook login * Creates Answers user from Facebook info if hasn't already been created * @param fb_user <associative array, keys: first_name, last_name, email, id> * Facebook User * @return boolean true on success, false on failure */ public static function auth_with_facebook($fb_user){ self::initialize(); // bail if already authorized with Answers creds if (self::$authorized){ return false; } $doctmpl = "<?xml version='1.0'?> <user> <name>%s</name> <email>%s</email> <facebookuser>%s</facebookuser> <network>facebook</network> <first-name>%s</first-name> <last-name>%s</last-name> <nickname></nickname> <profile-url></profile-url> <photo-url></photo-url> </user>"; $doc = sprintf($doctmpl, sprintf("%s %s", $fb_user['first_name'], $fb_user['last_name']), $fb_user['email'], $fb_user['id'], $fb_user['first_name'], $fb_user['last_name']); $headers = self::get_common_headers(); $response = self::put( self::$secure_host . self::EXTERNAL_AUTH_PATH, $doc, $headers ); $response = self::parse_response($response); //if response is false or has message attribute, then it was an error if ($response == false || (is_array($response) && array_key_exists('message', $response))) { self::$authorized = false; }else{ self::$authorized = true; } return self::$authorized; }