如果不是必需的,你需要使用imgur,那么我建议你尝试yfrog。
示例
抱歉,我没有时间编写 C# 示例,但这里是 PHP 示例:(source link)
<?php
/**
* This example demonstrates how to use OAuth credentials of your application to upload data to yfrog
* Usage: upload-to-yfrog-example.php <FILENAME-TO-UPLOAD>
*/
// TODO: PUT YOUR KEYS HERE
// your app's OAuth consumer & secret
define('OAUTH_CONSUMER_KEY', '');
define('OAUTH_CONSUMER_SECRET', '');
// your app user's token and secret, when twitter user granted access to your app
define('OAUTH_TOKEN_KEY', '');
define('OAUTH_TOKEN_SECRET', '');
// END OF TODO
// you can grab required file here:
// http://github.com/abraham/twitteroauth
require_once('OAuth.php');
// instantiating OAuth customer
$consumer = new OAuthConsumer(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);
// instantiating signer
$sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
// user's token
$token = new OAuthConsumer(OAUTH_TOKEN_KEY, OAUTH_TOKEN_SECRET);
// signing URL
$url = 'https://twitter.com/account/verify_credentials.xml';
$request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $url, array());
$request->sign_request($sha1_method, $consumer, $token);
$url = $request->to_url();
// OK, URL is signed, we can pass it to yfrog API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://yfrog.com/api/upload');
$post = array
(
'username' => 'yfrogtests', // twitter's username
'verify_url' => $url, // signed URL
'media' => '@' . $argv[1], // filename
'auth' => 'oauth', // auth=oauth is mandatory to use verify_url method
'message' => 'see it live on yfrog' // message to be sent, will not be posted to twitter
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
curl_close ($ch);
echo $response;
// see http://twitter.com/yfrogtests
?>
编辑:
正常流程表明
应用程序将请求令牌发送到
Twitter 中的 oauth/authorize
OAuth 的实现
规范。
访问令牌能持续多久?
我们目前没有使访问过期
令牌。您的访问令牌将是
如果用户明确拒绝则无效
您的应用程序从他们的设置
或者如果 Twitter 管理员暂停了你的
应用。如果您的应用程序是
暂停会有一个说明你
应用程序页面说它有
被暂停了。
来源:http://dev.twitter.com/doc
您需要拥有访问令牌,并且要获得它,用户需要首先批准您的应用程序 - 没有办法。
此外,您的应用程序可以对 1 个帐户进行的(写入)访问次数限制为每天约 300 次。因此,除非您的程序是为 1-3 人设计的,否则您将达到该限制。我的结论是:用户需要提供身份验证。