Send Private message with LinqToTwitter

风流意气都作罢 提交于 2020-01-06 17:39:13

问题


Hi i want to send private message with linqToTwitter, here is my code :

 var auth = new MvcAuthorizer
        {
            Credentials = new InMemoryCredentials()
            {
                ConsumerKey  = TwitterClient.ConsumerKey,
                ConsumerSecret = TwitterClient.ConsumerSecret,                    
                OAuthToken = TempData["AccessToken"] as string,
                AccessToken = TempData["TokenSecret"] as string
            }
        };            
        var twitterContext = new TwitterContext(auth);            
        var message = twitterContext.NewDirectMessage(auth.UserId, "Hi ucef, cool to discuss with you" + DateTime.Now);

but auth.UserId is null, have you any idea !!!


回答1:


The Authorizer will only hold a UserID immediately after you go through the OAuth process, where the user authenticates your app. After the user authenticates your app, Twitter sends back the UserID and ScreenName.

You're loading all 4 credentials at the same time, which gives the convenience of being able to query Twitter, without going through the OAuth process. However, since you didn't go through the OAuth process, there isn't a way to populate the UserID.

One way to work around this is to save the UserID after the first time the user authenticates and retrieve the saved ID from where you stored it on subsequent queries.

Another work around is to do an Account VerifyCredentials query. The you can get the UserID from the Account.User.UserIdentifier property.

Joe



来源:https://stackoverflow.com/questions/13053529/send-private-message-with-linqtotwitter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!