Tweetinvi-无法取消关注用户



我有以下代码,旨在找到您关注的用户以及您要求遵循的用户。然后,它取消了不关注您的人。但是,它实际上似乎从来没有工作,但是AuthenTicatedUser_unfollowuser返回true。有任何想法吗?谢谢。

            private void AuthenticateUser()
                    {
                        CheckRateLimits();
                        Auth.SetUserCredentials(_consumerKey, _consumerSecret, _userAccessToken, _userAccessSecret);
                        authenticatedUser = User.GetAuthenticatedUser();
                    }
                    private void CheckRateLimits()
                    {
                        // Enable RateLimit Tracking
                        RateLimit.RateLimitTrackerMode = RateLimitTrackerMode.TrackAndAwait;
                        TweetinviEvents.QueryBeforeExecute += (sender, args) =>
                        {
                            var queryRateLimits = RateLimit.GetQueryRateLimit(args.QueryURL);
                            // Some methods are not RateLimited. Invoking such a method will result in the queryRateLimits to be null
                            if (queryRateLimits != null)
                            {
                                if (queryRateLimits.Remaining > 0)
                                {
                                    AppendProgress("RateLimits Available : " + queryRateLimits.Remaining.ToString());
                                    // We have enough resource to execute the query
                                    return;
                                }
                                // Strategy #1 : Wait for RateLimits to be available
                                AppendProgress("Waiting for RateLimits until : " + queryRateLimits.ResetDateTime.ToLongTimeString() + "For " + queryRateLimits.ToString());
                                MessageBox.Show("Waiting for " + queryRateLimits.ResetDateTime.ToLongTimeString());
                                Thread.Sleep((int)queryRateLimits.ResetDateTimeInMilliseconds);
                                // Strategy #2 : Use different credentials
                                //var alternateCredentials = TwitterCredentials.CreateCredentials("", "", "", "");
                                //var twitterQuery = args.TwitterQuery;
                                //twitterQuery.OAuthCredentials = alternateCredentials;
                                // Strategy #3 : Cancel Query
                                //args.Cancel = true;
                            }
                        };
                    }
                  private void UnfollowUsersNotFollowingYou()
                    {
                        AuthenticateUser();
                        var toUnfollow = Examples.Friendship_GetUsersNotFollowingYou();
                        toUnfollow.ForEach(x =>
                        {
                            if (Examples.AuthenticatedUser_UnFollowUser(x.ScreenName))
                            {
                                AppendProgress("You have unfollowed " + x.ScreenName);
                                SaveUnfollowedUserIdToTextFile(x.ScreenName);
                            }
                        });
                    }
//From Examples Static Class                
                public static bool AuthenticatedUser_UnFollowUser(string userName)
                    {
                        var authenticatedUser = User.GetAuthenticatedUser();
                        var userToFollow = User.GetUserFromScreenName(userName);
                        bool unfollowed = authenticatedUser.UnFollowUser(userToFollow);
                        return unfollowed;
                    }
    //Users Not Following You
                public static IEnumerable<IUser> Friendship_GetUsersNotFollowingYou()
            {
                var currentuser = Examples.User_GetCurrentUserScreenname();
                var followers = Examples.User_GetFriendIds(currentuser);
                var following = Examples.Friendship_GetUsersYouRequestedToFollow();
                var toUnfollow = following.Where(x => followers != x.FriendIds);
                return toUnfollow;
            }

我是Tweetinvi的开发人员。我刚刚进行了验证,并且unfollow如下似乎可以正常工作。您能否验证您正在使用最新版本的Tweetinvi(0.9.13.0)?

另外,请注意,即使没有遵循用户,请访问将返回成功。这就是Twitter返回的,我对此无能为力。

编辑:

问题来自 @David-Beamont无法正确检索用户的事实。

这是获取以下用户的代码:

var authenticatedUser = User.GetAuthenticatedUser(); 
var friends = authenticatedUser.GetFriends();

相关内容

  • 没有找到相关文章

最新更新