Followers PM

Mar 18, 2014 at 2:53 PM
Hi,

I would like to send a personal message to all the users who are following me on twitter.

I use the following code:
TwitterCredentials.Credentials = TwitterCredentials.CreateCredentials(twitterAccessToken, twitterAccessTokenSecret, twitterAPIKey, twitterAPISecret);

var user = User.GetUserFromScreenName(screenName);
IEnumerable<TweetinviCore.Interfaces.IUser> followers = user.GetFollowers();
foreach (TweetinviCore.Interfaces.IUser follower in followers)
{
      var personalMessage = Message.CreateMessage(message, follower);
      personalMessage.Publish();
 }
But when it hits the Publish method i get an Argument Null Exception. If I take a closer look there is no sender specified and I can't seem to find a way to specify that sender.

Is there somebody who knows what I'm doing wrong?

Thanks in advance,
Kind Regards,
Arne Claerebout
Coordinator
Mar 18, 2014 at 3:33 PM
Hi

Twitter does not authorize to send messages to users who are not following you.
In the meantime, would you please let me know where you have this exception.

Also please be sure to have the latest version of Tweetinvi 0.9.4.0 which fixed a critical bug that could have make the Message.CreateMessage fails with a NullException.

Regards,
Linvi
Mar 18, 2014 at 3:47 PM
Hi,

I indeed, didn't have the latest version, though a new problem popped up after updating my nuget package. I now get the following exception:
{"The type initializer for 'Tweetinvi.TwitterCredentials' threw an exception."}

And the InnerException is:
{"Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"}

I already tried to update the assembly to the latest version but that is 6.1.0.0 to that's also not the version it's expecting.

Kind Regards,
Arne Claerebout
Coordinator
Mar 18, 2014 at 3:58 PM
Please download the dll and not from source code. There are apparently some conflict with pcl newtonsoft.json that I will fix tonight.

Linvi
Mar 18, 2014 at 4:00 PM
Hi,

Thanks for the quick replies!

Kind regards,
Arne Claerebout
Mar 18, 2014 at 4:12 PM
Linvi,

I'm now using the Merged Binaries dll from the Downloads section but I'm still getting the same error.
Currently I'm testing this in a limited environment where there are only 2 users following me and I'm following one user back.
It's that user I'm trying to send a PM to.

I'm fetching this user using the: user.GetFollowers() command.
Then I run over all the followers (there is only one), next i Create e message and then I try to publish it.

The program crashes when trying to publish it. I get an ArgumentNullException, with the following detail message:
Parameter type inference does not work for null values. Indicate the parameter type explicitly using a properly configured instance of the InjectionParameter or InjectionParameter<T> classes.
Parameter name: parameterValue

The sender parameter is still null.

Kind regards,
Arne Claerebout
Coordinator
Mar 18, 2014 at 4:17 PM
Hi,

You are saying that the follower list variable contains 1 user but that this user is null?

It had never happened to me but in this case the exception you receive is expected.

Would you please give me the if of the user you are trying to get the follower list from?

Linvi
Mar 18, 2014 at 4:30 PM
Hi,

No, so the GetFollowers() command gives me the following user (I guess a correct user):
Image

Next i run over all the users, so the first follower (see above screenshot) is used as the recipient in the CreateMessage statement. After creation this is the message:
Image

When the line personalMessage.Publish(); is hit, that's when the application crashed and gives the error posted in the previous message.
The null parameter i mentioned is the one you can see in the second screenshot under sender (could be it's supposed to be null, don't know.

Kind regards,
Arne Claerebout
Coordinator
Mar 18, 2014 at 4:41 PM
Hi,

The null parameter is expected for the sender but not for the receiver.

When you create a message this value is not set because you've just created it locally. You can decide to publish it with different credentials.
When the message is published successfully this parameter should be updated to a User that should be you.

I will have to go back to you tonight later as my lunch break is over.
Would you please send me the StackTrace as well as details of the exception you receive.

Linvi
Mar 18, 2014 at 7:22 PM
Edited Mar 18, 2014 at 7:23 PM
Hi,

Here is the complete error and stacktrace:
System.ArgumentNullException was unhandled
  HResult=-2147467261
  Message=Parameter type inference does not work for null values. Indicate the parameter type explicitly using a properly configured instance of the InjectionParameter or InjectionParameter<T> classes.
Parameter name: parameterValue
  Source=Tweetinvi.API
  ParamName=parameterValue
  StackTrace:
       at Microsoft.Practices.Unity.InjectionParameter.GetParameterType(Object parameterValue)
       at Microsoft.Practices.Unity.InjectionParameter..ctor(Object parameterValue)
       at Microsoft.Practices.Unity.InjectionParameterValue.ToParameter(Object value)
       at Microsoft.Practices.Unity.ParameterOverride..ctor(String parameterName, Object parameterValue)
       at TweetinviLogic.Wrapper.ParameterOverrideWrapper.get_ResolverOverride()
       at TweetinviFactories.UnityFactory`1.<Create>b__0(IResolverOverrideWrapper w)
       at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
       at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
       at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
       at TweetinviFactories.UnityFactory`1.Create(IResolverOverrideWrapper[] resolverOverrideWrappers)
       at TweetinviFactories.Direct_Messages.MessageFactory.GenerateMessageFromMessageDTO(IMessageDTO messageDTO)
       at TweetinviControllers.Messages.MessageController.PublishMessage(IMessageDTO messageDTO)
       at TweetinviLogic.Message.Publish()
       at Social_Media_Publisher.Program.PostOnTwitter(String message) in c:\Dropbox\Software\Social Media Publisher\Social Media Publisher\Social Media Publisher\Program.cs:line 70
       at Social_Media_Publisher.Program.Main(String[] args) in c:\Dropbox\Software\Social Media Publisher\Social Media Publisher\Social Media Publisher\Program.cs:line 23
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
Kind regards,
Arne Claerebout
Coordinator
Mar 18, 2014 at 7:39 PM
Thank you, I think I see what can go wrong.
If my theory is correct you are not allowed to post to the user. It implies that you are probably not followed by this user.

I will let you know.

Linvi
Mar 18, 2014 at 7:43 PM
Linvi,

I am following that user and that user is following me. It's another account I created to do some tests.
Also I'm using the .GetFollowers() method to fetch just those users who are following me.

Thanks again for the quick support!

Kind regards,
Arne Claerebout
Coordinator
Mar 19, 2014 at 1:25 AM
Edited Mar 19, 2014 at 1:56 AM
Hi,

The new version 0.9.0.7 is now available.
Please download and let me know how things go.

I believe the result of your publish will be false but lets find out.
// Get infos about an exception
var exception = ExceptionHandler.GetLastExption();
Regards,
Linvi
Mar 19, 2014 at 11:05 AM
Hi,

The application still crashes, If i check the exception i get a 401 error; Unauthorized - Authentication credentials were missing or incorrect.
Both the App and my access token have the following permissions: Read, write, and direct messages

Kind regards,
Arne Claerebout
Editor
Mar 19, 2014 at 11:08 AM
Edited Mar 19, 2014 at 11:09 AM
Hi Arne,

Make sure that you have permission to dm the user.

In order to send dm, you must follow the recipient and the recipient must follow you back. It's possible that you're not following all your followers.

Lokesh
Mar 19, 2014 at 11:51 AM
Hi Lokesh,

I checked again and we are both following each other, that's not the problem.
But i think i found out where the problem lies.

I'm using a comma in the message I'm sending and that seems to be where the error occurs. When I try to send the same message without the comma it works perfectly fine, so I tried to send "test, test" and that made it crash again.

So I'm guessing the "," value should be converted to it's percent encoded value: %2C.

Kind regards,
Arnde Claerebout
Coordinator
Mar 19, 2014 at 11:56 AM
Hi,

Sorry for that I did not thought to ask you for your message. I will have a look into it.

Linvi
Editor
Mar 19, 2014 at 11:57 AM
Yeah you're right. Hope we get a fix soon.
Mar 19, 2014 at 11:59 AM
Linvi,

No problem, we managed to find out what the problem was.
I'm very grateful for the great support!

At the moment I can manage without the , so you don't have to rush rush an update for me.

Kind regards,
Arne Claerebout