0

I have an array $fields with a screen_name and a count. No matter what I try, if I add them I get an error

Could not authenticate you.

One attempt was: $parameters = array_merge($oauth, $fields); I'm not gonna list all attempts cause that will just be noise.

Without using the parameter fields everything works ok. Can someone help, i'm totally lost here.

$settings = array(
    'oauth_access_token' => "304291054-X3AyJrHYUswZQbXXXXXXXXXXXXXOKw53xOi9E",
    'oauth_access_token_secret' => "iWuakK6iWsfXXXXXXXXXSGcW6WeqxLsiQf",
    'consumer_key' => "odXXXXXXXXXXkBg6GmsTg",
    'consumer_secret' => "5LoqUsXXXXXXXXXXXXXXXXi6zgmQ"
);

$base_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$http_method = 'GET';

$fields = array(
    'screen_name' => 'wearethegun',
    'count' => '5'
);


$oauth = array(
    'oauth_consumer_key' => $settings['consumer_key'],
    'oauth_nonce' => time(),
    'oauth_signature_method' => 'HMAC-SHA1',
    'oauth_token' => $settings['oauth_access_token'],
    'oauth_timestamp' => time(),
    'oauth_version' => '1.0'
);

// todo, fields
$parameters = $oauth;
ksort($parameters);


$base = $http_method.'&'.
        rawurlencode($base_url).'&'.
        rawurlencode(http_build_query($parameters));

$key = rawurlencode($settings['consumer_secret']).'&'.
       rawurlencode($settings['oauth_access_token_secret']);

$signature = base64_encode(hash_hmac('sha1', $base, $key, true));
$signature = rawurlencode($signature);


$oauth_header = '';
foreach ($oauth as $key => $value) {
    $oauth_header .= $key.'="'.$value.'", ';
}
$oauth_header .= 'oauth_signature="' . $signature . '"';


$curl_options = array(
    CURLOPT_HTTPHEADER => array("Authorization: Oauth {$oauth_header}", 'Expect:'),
    CURLOPT_HEADER => false,
    CURLOPT_URL => $base_url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 10,
);

$curl_request = curl_init();
curl_setopt_array($curl_request, $curl_options);
$json_str = curl_exec($curl_request);
curl_close($curl_request);

$json = json_decode($json_str, true);
echo "<pre>";
print_r($json);
echo "</pre>";
clankill3r
  • 9,146
  • 20
  • 70
  • 126

0 Answers0