hello i created a c# application that posts tweets and pictures on an account on twitter but im stuck with an error i can't seem to understand.
if someone ca help identify the problem i would appreciate it thanks!
here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TweetSharp;
using Hammock;
namespace TweetNow
{
class TweetManager
{
static public TwitterService initiate()
{
String _consumerKey = "epG4Cd8W06r8pxlt05I8Hg";
String _consumerSecret = "aattB5375aOn0tfpWSj0rdNUiYCwIfsQzwLGG1yVGFE";
String _accessToken = "479270385-Nda8X27zzi5xBKfUioNm9U8qCOzOvakVSGkS4YJS";
String _accessTokenSecret = "8rSKr6ph6oRJ4pISjZDny2mMyn4ldX1AoSHwtzx4";
TwitterService service = new TwitterService(_consumerKey, _consumerSecret);
service.AuthenticateWith(_accessToken, _accessTokenSecret);
return service;
}
public static void sendTweet(String msg,String picname,TwitterService serv) {
RestRequest request = serv.PrepareEchoRequest();
request.Path = "uploadAndPost.xml";
request.AddFile("media", "smile", "Images/"+picname, "image/jpeg");
request.AddField("key", "560adb8b7b328ae25ae3e7d3436de399");
request.AddField("message", "Emote with a Pic!");
RestClient client = new RestClient { Authority = "http://api.twitpic.com/", VersionPath = "2" };
RestResponse response = client.Request(request);
Console.WriteLine(response.Content);
String str = response.Content;
int first = str.IndexOf("<url>");
int last = str.LastIndexOf("</url>");
string str2 = str.Substring(first + 5, last - first - 5);
serv.SendTweet(msg+" "+str2+" .");
}
}
}
and the error i'm getting is :
system.ArgumentOutOfRangeException: Lenght cannot be less than yero.
Parameter name : length
at System.String.InternalSubStringWithChecks(int32 startIndex,Int32 length,Boolean fAlwaysCopy)
at TweetNow.TweetManager.sendTweet(String msg, String picname,TwitterService serv) in
d: ....