问题
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