Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php中的oauth身份验证通过api更新twitter状态_Php_Xml_Oauth_Twitter - Fatal编程技术网

使用php中的oauth身份验证通过api更新twitter状态

使用php中的oauth身份验证通过api更新twitter状态,php,xml,oauth,twitter,Php,Xml,Oauth,Twitter,我在谷歌上搜索了一段时间,没有搜索任何东西 如何使用php,使用OAuth通过twitter API更新twitter状态 谢谢 已经有一些为twitterapi编写的php类。只需选择一个并使用它。 Twitter开发者网站在其网站上列出了一系列类: 或者您可以使用pecl oauth库 我个人更喜欢使用pecl lib,这里有一个链接指向有用的文章: 以下是twitter状态更新的php代码: $body = array( 'status'=>'YOURMESSAGE' );

我在谷歌上搜索了一段时间,没有搜索任何东西

如何使用php,使用OAuth通过twitter API更新twitter状态


谢谢

已经有一些为twitterapi编写的php类。只需选择一个并使用它。 Twitter开发者网站在其网站上列出了一系列类:

或者您可以使用pecl oauth库

我个人更喜欢使用pecl lib,这里有一个链接指向有用的文章:


以下是twitter状态更新的php代码:

$body = array(
    'status'=>'YOURMESSAGE'
);
$url = "https://api.twitter.com/1.1/statuses/update.json";
$oauth_access_token = "YOURVALUE";
$oauth_access_token_secret = "YOURVALUE";
$consumer_key = "YOURVALUE";
$consumer_secret = "YOURVALUE";

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

$base_info = buildBaseString($url, 'POST', $oauth);
$composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$oauth['oauth_signature'] = $oauth_signature;
$header = array(buildAuthorizationHeader($oauth), 'Expect:');
$options = array( CURLOPT_HTTPHEADER => $header,
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HEADER => false,
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => false);

$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);

$result_data = json_decode($json);

function buildBaseString($baseURI, $method, $params) {
$r = array();
ksort($params);
foreach($params as $key=>$value){
    $r[] = "$key=" . rawurlencode($value);
}
return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
}

function buildAuthorizationHeader($oauth) {
$r = 'Authorization: OAuth ';
$values = array();
foreach($oauth as $key=>$value)
    $values[] = "$key=\"" . rawurlencode($value) . "\"";
$r .= implode(', ', $values);
return $r;
}