如何使用twitter api与"http basic auth"?

ahm*_*med 2 php authentication api twitter

如何使用twitter api与"http basic auth"?

我想我应该使用"消费者密钥"!因为twitter给了你每小时的限制请求率,如果我不使用我的消费者密钥,他们如何计算我的请求?

Jus*_*iey 5

每当你想对任何东西使用HTTP基本身份验证时,如果你想忽略实际的实现和HTTP头,只需使用cURL.这是PHP中的一个简单示例,cURL也可以使用其他语言:

<?php
$ch = curl_init();
// Sets the URL cURL will open
curl_setopt($ch, CURLOPT_URL, 'http://twitter.com/statuses/user_timeline.xml?screen_name=al3x');
// Here's the HTTP auth
// The 3rd argument is your Twitter username and password joined with a colon
curl_setopt($ch, CURLOPT_USERPWD, 'username:password');
// Makes curl_exec() return server response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Lately the Twitter API expects an Expect header. It's a mystery
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
// And here's the result XML
$twitter_xml = curl_exec($ch);
curl_close($ch);
?>
Run Code Online (Sandbox Code Playgroud)

然后$twitter_xml将包含al3x公共时间轴的XML.就限速而言,ceejayoz已经很好地回答了这个问题.