0

我尝试向已通过 my_app 身份验证的用户的关注者发送私人消息,代码如下:

    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 是经过身份验证的用户的关注者列表。

Pleaaaase 我需要你的帮助。

4

1 回答 1

0

解决方案是使用 InMemoryCrendentials 而不是 SessionStateCredentials 并将令牌秘密添加到 crendential 中,然后我们应该将 DateTime.Now 添加到消息中,因为 twitter 不允许重复消息,这是解决方案中的代码,它运行良好:

  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()));

谢谢

于 2012-06-18T11:05:43.167 回答