本文整理汇总了C#中TweetSharp.TwitterService.SendTweetWithMedia方法的典型用法代码示例。如果您正苦于以下问题:C# TwitterService.SendTweetWithMedia方法的具体用法?C# TwitterService.SendTweetWithMedia怎么用?C# TwitterService.SendTweetWithMedia使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TweetSharp.TwitterService
的用法示例。
在下文中一共展示了TwitterService.SendTweetWithMedia方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetStatusAsync
/// <summary>
/// Sets an user status.
/// </summary>
/// <param name="status">Status entity.</param>
public async Task SetStatusAsync(TwitterStatus status)
{
// Pass your credentials to the service
string consumerKey = _settings.TwitterConsumerKey;
string consumerSecret = _settings.TwitterConsumerSecret;
// Authorize
var service = new TwitterService(consumerKey, consumerSecret);
service.AuthenticateWith(status.Token, status.TokenSecret);
// Send message
TweetSharp.TwitterStatus result;
if (string.IsNullOrEmpty(status.ScreenshotUrl))
{
var tweet = new SendTweetOptions { Status = status.Message };
result = service.SendTweet(tweet);
}
else
{
using (var httpClient = new HttpClient())
{
HttpResponseMessage response = await httpClient.GetAsync(status.ScreenshotUrl);
if (!response.IsSuccessStatusCode)
{
throw new BadRequestException(response.ReasonPhrase);
}
Stream stream = await response.Content.ReadAsStreamAsync();
var tweet = new SendTweetWithMediaOptions
{
Status = status.Message,
Images = new Dictionary<string, Stream>
{
{ "media", stream }
}
};
result = service.SendTweetWithMedia(tweet);
}
}
// Check result status
if (result != null)
{
return;
}
// Check response status code
switch (service.Response.StatusCode)
{
case HttpStatusCode.Unauthorized:
case HttpStatusCode.BadRequest:
// Invalid credentials or request data
throw new BadRequestException(service.Response.Response);
case HttpStatusCode.Forbidden:
throw new ForbiddenException(service.Response.Response);
case (HttpStatusCode)429:
throw new TooManyRequestsException(service.Response.Response);
}
// Twitter internal errors
if ((int)service.Response.StatusCode >= 500)
{
throw new BadGatewayException(service.Response.Response);
}
string message = string.Format("Unable to send tweet. Status code {0}: {1}", service.Response.StatusCode, service.Response);
throw new InternalServerErrorException(message);
}
示例2: TweetWithImage
public void TweetWithImage()
{
try
{
//ステータスリスト
List<TwitterService> ResponseList = new List<TwitterService>();
//各アカウントでつぶやく
foreach (Core.ApplicationSetting.AccountClass account in AccountList)
{
//ファイルのストリームを取得
System.IO.Stream stream = Song.getAlbumArtworkFileStream();
TwitterService service = new TwitterService(Core.Twitter.CONSUMERKEY, Core.Twitter.CONSUMERSECRET);
service.AuthenticateWith(account.Token, account.TokenSecret);
SendTweetWithMediaOptions opt = new SendTweetWithMediaOptions();
opt.Status = Core.Replace.ReplaceText(TweetText, Song); // ツイートする内容
//テキストを自動的に削るやつ
if (AutoDeleteText == true && opt.Status.Length > 117)
{
opt.Status = opt.Status.Remove(114);//...の三文字分含めて削除
opt.Status += "...";
}
//opt.Status = HttpUtility.UrlEncode(opt.Status);
opt.Images = new Dictionary<string, System.IO.Stream> { { "image", stream } };
//Luaの関数を走らせる
try
{
bool luaRet = (bool)luaFunc.Call(Song, opt, isCustomTweet)[0];
if (luaRet == true)
{
service.SendTweetWithMedia(opt);
ResponseList.Add(service);
}
}
catch (Exception ex2)
{
//Luaが失敗しても死なないようにする
Trace.WriteLine("Lua error.");
Trace.WriteLine(ex2.ToString());
service.SendTweetWithMedia(opt);
ResponseList.Add(service);
}
stream.Close();
stream.Dispose();
}
//完了イベントを投げる
onProcessFinished(ResponseList);
}
catch (Exception ex)
{
Trace.WriteLine("[TwitterPost ERROR]" + ex.ToString());
}
}
示例3: SendImageMessage
private static TwitterStatus SendImageMessage(TwitterService service, MessageEntity message)
{
TwitterStatus status = null;
try
{
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(message.Message);
WebResponse myResp = myReq.GetResponse();
using (Stream stream = myResp.GetResponseStream())
using (MemoryStream ms = new MemoryStream())
{
int count = 0;
do
{
byte[] buf = new byte[1024];
count = stream.Read(buf, 0, 1024);
ms.Write(buf, 0, count);
} while (stream.CanRead && count > 0);
status = service.SendTweetWithMedia(new SendTweetWithMediaOptions()
{
Status = message.Message,
DisplayCoordinates = false,
Images = new Dictionary<string, Stream>()
{
{message.TwitterNick, ms}
}
});
}
}
catch (Exception ex)
{
Extentions.ConsoleWriteLine(ex.Message, ConsoleColor.Red);
}
return status;
}
示例4: m_oWorker_DoWork
/// <summary>
/// Uploading image, done on a different thread. </br>
/// </summary>
/// <param name="sender"></param>
/// <param name="e"> Contains the </param>
private void m_oWorker_DoWork(object sender, DoWorkEventArgs e)
{
List<Object> args = (List<Object>) e.Argument;
//Get the elements
String message = (String) args[0];
BitmapSource bitsource = (BitmapSource) args[1];
Stream stream = args[2] as MemoryStream;
Console.WriteLine("Uploading image now");
var service = new TwitterService(OAuthConsumerKey, OAuthConsumerSecret);
service.AuthenticateWith(OAuthToken, OAuthTokenSecret);
SendTweetWithMediaOptions options = new SendTweetWithMediaOptions();
options.Status = message;
var dic = new Dictionary<string, Stream>();
dic.Add(message, stream);
options.Images = dic;
service.SendTweetWithMedia(options);
//Report 100% completion on operation completed
worker.ReportProgress(100);
}