public function fetch($url, $requestData = array()) { $requestData['profile']['name'] = $this->name; $response = xhttp::fetch($url, $requestData); self::$datastore[$this->name]['response'] = $response; return $response; }
public function call($url, $method, $parameters, $options = array()) { $options = array_merge(array('verbosity' => 'no_white_space'), $options); $data['post'] = xmlrpc_encode_request($method, $parameters, $options); $data['post'] = str_replace(array('<string><base64>', '</base64></string>'), array('<base64>', '</base64>'), $data['post']); $data['headers']['Content-Type'] = 'text/xml'; $data['method'] = 'post'; xhttp::addHookToRequest($data, 'data-preparation', array(__CLASS__, 'set_rpc_data'), 8); $response = xhttp::fetch($url, $data); $response['raw'] = $response['body']; $response['body'] = str_replace('i8>', 'i4>', $response['body']); $response['body'] = xmlrpc_decode($response['body']); if ($response['body'] and xmlrpc_is_fault($response['body'])) { $response['rpc_fault'] = $response['body']['faultString']; $response['rpc_fault_code'] = $response['body']['faultCode']; } return $response; }
// Extract Auth preg_match('/Auth=(.+)/', $response['body'], $matches); $auth = $matches[1]; // You can also cache this auth value for at least 5+ minutes // Erase POST variables used on the previous xhttp call $data['post'] = null; // Set Authorization for authentication // There is no official documentation and this might change without notice $data['headers'] = array('Authorization' => 'GoogleLogin auth=' . $auth); $response = xhttp::fetch('https://www.google.com/voice/b/0', $data); if (!$response['successful']) { echo 'response: '; print_r($response); die; } // Extract _rnr_se | This value does not change* Cache this value preg_match("/'_rnr_se': '([^']+)'/", $response['body'], $matches); $rnrse = $matches[1]; // $data['headers'] still contains Auth for authentication // Set SMS options $data['post'] = array('_rnr_se' => $rnrse, 'phoneNumber' => $argv[1], 'text' => $argv[2], 'id' => ''); // Send the SMS $response = xhttp::fetch('https://www.google.com/voice/sms/send/', $data); // Evaluate the response $value = json_decode($response['body']); if ($value->ok) { } else { echo "Unable to send SMS! Error Code ({$value->data->code})\n\n"; echo 'response: '; print_r($response); }
$response = xhttp::fetch('https://graph.facebook.com/oauth/access_token', $data); if($response['successful']) { $data = xhttp::toQueryArray($response['body']); $_SESSION['access_token'] = $data['access_token']; $_SESSION['loggedin'] = true; $data = array(); $data['get'] = array( 'access_token' => $_SESSION['access_token'], 'fields' => 'id,name,accounts' ); $response = xhttp::fetch('https://graph.facebook.com/me', $data); if($response['successful']) { $_SESSION['user'] = json_decode($response['body'], true); $_SESSION['user']['access_token'] = $_SESSION['access_token']; } else { header('content-type: text/plain'); print_r($response['body']); } } else { print_r($response['body']); } }