Exemple #1
0
function follow($id)
{
    $postfields = array('access_token' => $_SESSION['token'], 'action' => 'follow');
    $url = "https://api.instagram.com/v1/users/" . $id . "/relationship";
    $sig = generate_sig("/users/" . $id . "/relationship", $postfields, $secret);
    $postfields["sig"] = $sig;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
    $server_output = curl_exec($ch);
    curl_close($ch);
    return json_decode($server_output);
}
 public function post_request($method, $params)
 {
     $params['method'] = $method;
     $params['session_key'] = $this->session_key;
     $params['api_key'] = $this->api_key;
     $params['call_id'] = microtime(true);
     if (!isset($params['v'])) {
         $params['v'] = '1.0';
     }
     $post_params = array();
     foreach ($params as $key => &$val) {
         if (is_array($val)) {
             $val = implode(',', $val);
         }
         $post_params[] = $key . '=' . urlencode($val);
     }
     if ($this->desktop && $method != 'facebook.auth.getSession' && $method != 'facebook.auth.createToken') {
         $secret = $this->session_secret;
     } else {
         $secret = $this->secret;
     }
     $post_params[] = 'sig=' . generate_sig($params, $secret);
     $post_string = implode('&', $post_params);
     // Use CURL if installed
     if (function_exists('curl_init')) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $this->server_addr);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_USERAGENT, 'Facebook API PHP5 Client 1.0 (curl) ' . phpversion());
         $result = curl_exec($ch);
         curl_close($ch);
     } else {
         // non-curl based version...
         // Using fopen with ssl transport requires OpenSSL to be installed.
         if (strncmp($this->server_addr, 'https', 5) == 0 && function_exists('openssl_open')) {
             $protocol = 'https';
         } else {
             // switch back to http
             $protocol = 'http';
             $this->server_addr = str_replace('https://', 'http://', $this->server_addr);
         }
         $context = array($protocol => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded' . "\r\n" . 'User-Agent: Facebook API PHP5 Client 1.0 (non-curl) ' . phpversion() . "\r\n" . 'Content-length: ' . strlen($post_string), 'content' => $post_string));
         $contextid = stream_context_create($context);
         $sock = fopen($this->server_addr, 'r', false, $contextid);
         if ($sock) {
             $result = '';
             while (!feof($sock)) {
                 $result .= fgets($sock, 4096);
             }
             fclose($sock);
         }
     }
     return $result;
 }