Question

i try to send private message to followers of a user who is already authenticated with my_app, here is the code :

    var authent = new MvcAuthorizer
        {
            Credentials = new SessionStateCredentials()
            {
                ConsumerKey = this.client.ConsumerKey,
                ConsumerSecret = this.client.ConsumerSecret,
                OAuthToken = identity.Token.Token
            }
        };

        var twitterCtx = new TwitterContext(authent);
        list_friend.ToList().ForEach(x => twitterCtx.NewDirectMessage(x.InvitedFriendID, messageWithPlaceHolders.Replace("[FRIEND_NAME]", x.Name)));

list_friend is the list of followers of the user who is authenticated.

Pleaaaase i need your help.

Was it helpful?

Solution

the solution is to use the InMemoryCrendentials rather than SessionStateCredentials and add the token secret to crendential, and after we should add DateTime.Now to the message because twitter don't allow duplicate message, here is the code off the solution it work well :

  var authent = new MvcAuthorizer
        {
            Credentials = new InMemoryCredentials()
            {
                ConsumerKey = this.client.ConsumerKey,
                ConsumerSecret = this.client.ConsumerSecret,
                OAuthToken = identity.Token.Token,
                AccessToken = identity.Token.Secret
            }
        };
  var twitterCtx = new TwitterContext(authent);            
  list_friend.ToList().ForEach(x => twitterCtx.NewDirectMessage(x.SocialId, messageWithPlaceHolders.Replace("[FRIEND_NAME]", x.Name) +DateTime.Now.ToString()));

Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top