我有以下代码,旨在查找您关注的用户以及您要求关注的用户。然后它取消了那些没有跟随你的人。但是它实际上似乎没有工作,但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;
}
答案 0 :(得分:0)
我是Tweetinvi的开发者。我刚刚验证过,unfollow
喜欢关注似乎正常工作。您能否确认您使用的是最新版本的Tweetinvi(0.9.13.0)?
另请注意,即使没有关注用户,取消关注也会返回成功。这就是Twitter的回归,我无能为力。
编辑:
问题来自@ david-beamont没有正确检索用户的事实。
以下是获取以下用户的代码:
var authenticatedUser = User.GetAuthenticatedUser();
var friends = authenticatedUser.GetFriends();