Click here to Skip to main content
16,017,707 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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";
            // Pass your credentials to the service
            TwitterService service = new TwitterService(_consumerKey, _consumerSecret);

            //  Retrieve an OAuth Request Token
            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", "b9deee8ea5af8a6e1bac2aeb9d541c46"); 
            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: ....
Posted
Updated 8-Jul-13 2:44am
v2
Comments
ZurdoDev 8-Jul-13 8:44am    
The error tells you the problem. Which line is it?

From the error, I guess that str2 is either blank or null.
Because you can't tweet blank values.

And see the codes before str2, I apprehend that you are not getting anything in str in the below line.
C#
String str = response.Content;


Please debug your code and find out where exactly you are not getting values.
 
Share this answer
 
Comments
THESIS_NAIM 9-Jul-13 4:42am    
hello,
i found out that response.Content in empty its giving me bad authentication data error code 215
does anyone know what this means and what can i do to fix it??
I would suggest you to look at the links suggested by Google.
you were right,i actually found out before u post ur answer but you guessed it
but now im facing another problem,the response.Content is saying header rejected by twitter what can i do to solve this? any ideas?
and thanks again for helping me :))
 
Share this answer
 
Comments
Please delete this as it is not an answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900