Beginner - Help

Sep 17, 2014 at 10:23 AM
Hey there,

I just started working on my first API project in Uni, and decided to use Tweetinvi for it.

However, for some reason, I am not being able to either post or get anything from Twitter. All the credentials have been added, but nothing happens. Can you tell me what is wrong with my code?

Thanks.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tweetinvi;


namespace TSA
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            TwitterCredentials.SetCredentials("xxxxx", "xxxxx", "xxxxx", "xxxxx");

            TwitterCredentials.ApplicationCredentials = TwitterCredentials.CreateCredentials("xxxxx", "xxxxx", "xxxxx", "xxxxx");
        }

        private void button1_Click(object sender, EventArgs e)
        {

           

            var tweet = Tweetinvi.Tweet.PublishTweet("C# API Test");
            var tweets = Search.SearchTweets("tweetinvi");
            Console.WriteLine(tweets);


        }
    }
}
Sep 17, 2014 at 2:18 PM
Edited Sep 17, 2014 at 2:21 PM
Hi Luka,

I have not updated the version of TweetInvi I'm using in a while now, so how things work may have changed, but it's worth a shot atleast.

Remove this line
        TwitterCredentials.ApplicationCredentials = TwitterCredentials.CreateCredentials("xxxxx", "xxxxx", "xxxxx", "xxxxx");

and try building the app again, failing that move the line
        TwitterCredentials.ApplicationCredentials = TwitterCredentials.CreateCredentials("xxxxx", "xxxxx", "xxxxx", "xxxxx");
above
   TwitterCredentials.SetCredentials("xxxxx", "xxxxx", "xxxxx", "xxxxx");
So you'd want:
        TwitterCredentials.ApplicationCredentials = TwitterCredentials.CreateCredentials("xxxxx", "xxxxx", "xxxxx", "xxxxx");

        TwitterCredentials.SetCredentials("xxxxx", "xxxxx", "xxxxx", "xxxxx");


In my apps, I only need the .SetCredentials line, but if you require both I believe .CreateCredentials would need to be called before .SetCredentials. (You can't set something before it's been created)


Failing that could you post the error you're getting?
Sep 17, 2014 at 3:43 PM
Hey Phoenix2105,

Thank you for helping me out.

I have tried all of your recommendations, but still I am not able to make this work. I have also tried disabling the firewall, but no luck.

There are no errors during the execution, and this is what I get via Debug output:
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\Users\Luka\documents\visual studio 2013\Projects\TSA\TSA\bin\Debug\TSA.vshost.exe'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Deployment\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 0x1ec8 has exited with code 259 (0x103).
The thread 0x2e8 has exited with code 259 (0x103).
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\Users\Luka\documents\visual studio 2013\Projects\TSA\TSA\bin\Debug\TSA.exe'. Symbols loaded.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\Users\Luka\documents\visual studio 2013\Projects\TSA\TSA\bin\Debug\Tweetinvi.dll'. Cannot find or open the PDB file.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\Users\Luka\documents\visual studio 2013\Projects\TSA\TSA\bin\Debug\Tweetinvi.Core.dll'. Cannot find or open the PDB file.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\Users\Luka\documents\visual studio 2013\Projects\TSA\TSA\bin\Debug\Autofac.dll'. Cannot find or open the PDB file.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\Users\Luka\documents\visual studio 2013\Projects\TSA\TSA\bin\Debug\Tweetinvi.Controllers.dll'. Cannot find or open the PDB file.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\Users\Luka\documents\visual studio 2013\Projects\TSA\TSA\bin\Debug\Tweetinvi.Credentials.dll'. Cannot find or open the PDB file.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\Users\Luka\documents\visual studio 2013\Projects\TSA\TSA\bin\Debug\Tweetinvi.Factories.dll'. Cannot find or open the PDB file.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\Users\Luka\documents\visual studio 2013\Projects\TSA\TSA\bin\Debug\Tweetinvi.Logic.dll'. Cannot find or open the PDB file.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\Users\Luka\documents\visual studio 2013\Projects\TSA\TSA\bin\Debug\Tweetinvi.WebLogic.dll'. Cannot find or open the PDB file.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\Users\Luka\documents\visual studio 2013\Projects\TSA\TSA\bin\Debug\Tweetinvi.Streams.dll'. Cannot find or open the PDB file.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\Users\Luka\documents\visual studio 2013\Projects\TSA\TSA\bin\Debug\Newtonsoft.Json.dll'. Cannot find or open the PDB file.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.dll'. Cannot find or open the PDB file.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'Anonymously Hosted DynamicMethods Assembly'. 
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\Users\Luka\documents\visual studio 2013\Projects\TSA\TSA\bin\Debug\Tweetinvi.Security.dll'. Cannot find or open the PDB file.
'TSA.vshost.exe' (CLR v4.0.30319: TSA.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
POST : https://api.twitter.com/1.1/statuses/update.json?status=C%23%20API%20Test&trim_user=true
Header OAuth oauth_consumer_key="xxxxx",oauth_nonce="6496209",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1410968446",oauth_token="xxxxx",oauth_version="1.0",oauth_signature="yG0q3nL3ZzzDIzdhcQf3QunUiSc%3D"
GET : https://api.twitter.com/1.1/search/tweets.json?q=tweetinvi&result_type=Mixed
Header OAuth oauth_consumer_key="xxxxx",oauth_nonce="4364041",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1410968448",oauth_token="xxxxx",oauth_version="1.0",oauth_signature="ULpyAXJd7H6vPsxIYlkx5rOhp70%3D"
System.Collections.Generic.List`1[Tweetinvi.Core.Interfaces.ITweet]
The thread 0x1e08 has exited with code 259 (0x103).
The thread 0x1c2c has exited with code 259 (0x103).
The program '[1312] TSA.vshost.exe' has exited with code 0 (0x0).
The program '[1312] TSA.vshost.exe: Program Trace' has exited with code 0 (0x0).
Sep 17, 2014 at 4:00 PM
Edited Sep 17, 2014 at 4:06 PM
Well you have a few " Cannot find or open the PDB file." errors but they shouldn't matter too much as these are files for debugging.
And I cant see any other errors, can you open a command prompt and try pinging twitter's API server?

So if you don't know : Run > Cmd > Enter > ping api.twitter.com > Enter

And tell me whether you get a response back from the server?

If I cannot help you fix this problem, I'm sure Linvi can.


Another thing I just need to double check
Header OAuth oauth_consumer_key="xxxxx",oauth_nonce="6496209",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1410968446",oauth_token="xxxxx",oauth_version="1.0",oauth_signature="yG0q3nL3ZzzDIzdhcQf3QunUiSc%3D"
GET : https://api.twitter.com/1.1/search/tweets.json?q=tweetinvi&result_type=Mixed
Header OAuth oauth_consumer_key="xxxxx",oauth_nonce="4364041",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1410968448",oauth_token="xxxxx",oauth_version="1.0",oauth_signature="ULpyAXJd7H6vPsxIYlkx5rOhp70%3D"

Did you 'xxxx' out these variables before posting? I'm guessing you did, which is fine, just checking you're not using "xxxx" as your consumer key :P :).

The other thing I would check is that your developer account has "Read and Write" permissions, this is also where you can view your API/Access token and API/Access Secret

You can check this at https://apps.twitter.com/ - If you modify any settings it may take a few minutes to update any changes.
Sep 17, 2014 at 5:12 PM
Yeah, I guess PDB files are purely related to library and debugging, so it shouldn't be an issue.

Successfully pinged api.twitter.com!

When it comes to permissions, I have enabled read & write now, but even after a few attempts no tweets have been posted to my Twitter profile.

Yeah, I masked keys for security reasons, I am using the right ones :D

I guess we'll have to wait for Linvi. I appreciate your help Phoenix! :)
Editor
Sep 17, 2014 at 10:07 PM
Your debug output seems perfectly fine.

GET : https://api.twitter.com/1.1/search/tweets.json?q=tweetinvi&result_type=Mixed
Header OAuth oauth_consumer_key="xxxxx",oauth_nonce="4364041",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1410968448",oauth_token="xxxxx",oauth_version="1.0",oauth_signature="ULpyAXJd7H6vPsxIYlkx5rOhp70%3D"
System.Collections.Generic.List`1[Tweetinvi.Core.Interfaces.ITweet]
The thread 0x1e08 has exited with code 259 (0x103)

Your Console.WriteLine(tweets); is also working as expected here. Can you do a MessageBox.Show(tweets.Count())? I feel you're missing something very obvious here.
Sep 18, 2014 at 9:08 AM
Just checked Twitter's API status and the userstream service has been down for two days now, I'm not entirely sure if the userstream service being down would affect your ability to post tweets, but I thought it worth mentioning.

https://dev.twitter.com/overview/status
Sep 18, 2014 at 9:17 AM
Hm, I cannot call Count() on tweets. I have Count<>, but that is not what we are looking for.
Editor
Sep 18, 2014 at 12:48 PM
Edited Sep 18, 2014 at 12:57 PM
You need:

using System.Linq;

You'll need a reference to "System.Core".

I just thought that you should make sure that the call to search is actually not working. Because you only mention about the tweet not getting posted to the profile.

Your console.WriteLine is working as expected. Maybe you can break at the console.WriteLine call and check the value of tweets in the debugger.

Or just do:
MessageBox.Show(tweets.ToArray()[0].Text);
Marked as answer by LukaV on 9/19/2014 at 7:49 AM
Sep 18, 2014 at 1:47 PM
Dear imlokesh please take a look at your email

thanks mate
Sep 19, 2014 at 9:29 AM
Working! Thanks imlokesh!

Just one question: I ran a search with #poplave hashtag (floods in Serbia, a lot of tweets) but got only 15 elements in array. Is there a way to pull more? The idea is to run sentiment analysis on pulled tweets.
Editor
Sep 19, 2014 at 10:11 AM
Edited Sep 19, 2014 at 10:24 AM
Cool. :)
var param = Search.GenerateTweetSearchParameter("#poplave");
param.MaxId = -1;
param.MaximumNumberOfResults = 100;
var results = Search.SearchTweets(param);

param.MaxId = results.LastOrDefault().Id - 1;
var newResults = Search.SearchTweets(param);
You can use the maxid to search for older tweets like this. It's best if you can create a function that takes the maxid and recursively calls itself until you've the desired number of results. I think the search is limited to 3200 tweets for a given keyword.

Also, I am not sure, maybe linvi has taken care of this internally in tweetinvi. Try setting MaximumNumberOfResults to like 500. Maybe it'll work without hacking around.

About your status not getting updated. Make sure you're checking the right account. :P

@flexair You've a reply. :)

imlokesh
Marked as answer by LukaV on 9/19/2014 at 7:49 AM