linvi / tweetinvi

Tweetinvi, an intuitive Twitter C# library for the REST and Stream API. It supports .NET, .NETCore, UAP (Xamarin)...
MIT License
1k stars 220 forks source link

Forums or better explainations #717

Open ForDebating opened 6 years ago

ForDebating commented 6 years ago

Hello.

Where are the forums where this plugin can be discussed? I'm trying to create a few simple twitter APIs with C#:

1) all my followers in a text file 2) all users who follow me in a text file 3) follow all users in a text file 4) unfollow all users in a text file 5) send a direct message to users in a text file

I want to run 1 and 2 daily. From that, I'll use compare software and use 3 to follow everyone who I'm not following back, and 5 to send them a message thanking them for following me. 3 days later I'll compare who I follow and who don't follow me back and use 4 to unfollow them. If they weren't following me before but are now I'll use 5 to thank them for following me back. Seems like this should be pretty easy to code but I have never programmed before. I've been trying to do this manually and it's eating a ton of my time so I'm giving this a try. I've read https://github.com/linvi/tweetinvi/wiki/Get-All-Followers-Code and https://github.com/linvi/tweetinvi/blob/master/Examplinvi.NETFramework/Program.cs several times, spent several hours banging my head, and can't get it working. Thus far I'm just working on the get followers part and I can't get it to even pull users. (much less sending it to a text file)

I got this working:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tweetinvi;

namespace Twitter_Console
{
    class Program
    {
        static void Main(string[] args)
        {
            Auth.SetUserCredentials("z...P", "s...l", "9..2-G..6", "o..8");

            var user = User.GetAuthenticatedUser();

            Tweet.PublishTweet("Can't sleep.");
        }
    }
}

But the follow users doesn't work:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Reflection;

// REST API
using Tweetinvi;
using Tweetinvi.Models;
using Tweetinvi.Parameters;

// STREAM API
using Tweetinvi.Streaming;
using Stream = Tweetinvi.Stream;

// Others
using Tweetinvi.Exceptions; // Handle Exceptions
using Tweetinvi.Core.Extensions;
using Tweetinvi.Core.Public.Parameters;
// Extension methods provided by Tweetinvi
using Tweetinvi.Models.DTO; // Data Transfer Objects for Serialization
using Tweetinvi.Json; // JSON static classes to get json from Twitter.

// ReSharper disable UnusedVariable
namespace Examplinvi

namespace Get_Followers
{
    class Program
  {
     static void Main(string[] args)
     RateLimit.RateLimitTrackerMode = RateLimitTrackerMode.TrackOnly;

     long nextCursor = -1;

     do
     {
        var followerIds = GetFollowerIds("fordebatingcom", nextCursor, out nextCursor);
        // Your method to process the follower ids : ProcessFollowerIds(followerIds);
     } 
     while (nextCursor != -1 && nextCursor != 0);

     private static IEnumerable<IIdsCursorQueryResultDTO> GetFollowerIds(string username, long cursor, out long nextCursor)
      {
        var query = string.Format("https://api.twitter.com/1.1/followers/ids.json?screen_name={0}", username);

        // Ensure that we can get some information
        RateLimit.AwaitForQueryRateLimit(query);
        var results = TwitterAccessor.ExecuteCursorGETCursorQueryResult<IIdsCursorQueryResultDTO>(query, cursor: cursor).ToArray();

        if (!results.Any())
        {
            // Something went wrong. The RateLimits operation tokens got used before we performed our query
            RateLimit.ClearRateLimitCache();
            RateLimit.AwaitForQueryRateLimit(query);
            results = TwitterAccessor.ExecuteCursorGETCursorQueryResult<IIdsCursorQueryResultDTO>(query, cursor: cursor).ToArray();
        }

        if (results.Any())
        {
            nextCursor = results.Last().NextCursor;
        }

        else
        {
            nextCursor = -1;
        }

        return results;
      }
   }
}

These are the errors it gives me:

Severity    Code    Description Project File    Line    Suppression State
Error   CS1514  { expected  Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   29  Active
Error   CS0501  'Program.Main(string[])' must declare a body because it is not marked abstract, extern, or partial  Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   35  Active
Error   CS1002  ; expected  Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   36  Active
Error   CS1519  Invalid token '=' in class, struct, or interface member declaration Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   36  Active
Error   CS1519  Invalid token '=' in class, struct, or interface member declaration Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   36  Active
Error   CS1519  Invalid token ';' in class, struct, or interface member declaration Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   36  Active
Error   CS1519  Invalid token ';' in class, struct, or interface member declaration Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   36  Active
Error   IDE1007 The name 'RateLimit.RateLimitTrackerMode' does not exist in the current context.    Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   36  Active
Error   IDE1007 The name 'RateLimitTrackerMode' does not exist in the current context.  Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   36  Active
Error   IDE1007 The name 'RateLimitTrackerMode.TrackOnly' does not exist in the current context.    Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   36  Active
Error   IDE1007 The name 'TrackOnly' does not exist in the current context. Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   36  Active
Error   CS1519  Invalid token 'do' in class, struct, or interface member declaration    Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   40  Active
Error   CS0825  The contextual keyword 'var' may only appear within a local variable declaration or in script code  Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   42  Active
Error   CS0103  The name 'GetFollowerIds' does not exist in the current context Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   42  Active
Error   CS0236  A field initializer cannot reference the non-static field, method, or property 'Program.nextCursor' Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   42  Active
Error   CS0236  A field initializer cannot reference the non-static field, method, or property 'Program.nextCursor' Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   42  Active
Error   CS1022  Type or namespace definition, or end-of-file expected   Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   45  Active
Error   CS1026  ) expected  Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   45  Active
Error   CS8124  Tuple must contain at least two elements.   Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   45  Active
Error   CS1022  Type or namespace definition, or end-of-file expected   Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   45  Active
Error   CS0116  A namespace cannot directly contain members such as fields or methods   Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   45  Active
Error   CS1022  Type or namespace definition, or end-of-file expected   Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   45  Active
Error   IDE1007 The name 'nextCursor' does not exist in the current context.    Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   45  Active
Error   IDE1007 The name 'nextCursor' does not exist in the current context.    Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   45  Active
Error   CS0246  The type or namespace name 'IIdsCursorQueryResultDTO' could not be found (are you missing a using directive or an assembly reference?)  Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   47  Active
Error   CS0116  A namespace cannot directly contain members such as fields or methods   Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   47  Active
Error   CS0246  The type or namespace name 'IIdsCursorQueryResultDTO' could not be found (are you missing a using directive or an assembly reference?)  Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   53  Active
Error   CS0246  The type or namespace name 'IIdsCursorQueryResultDTO' could not be found (are you missing a using directive or an assembly reference?)  Get_Followers   C:\Users\Coveny\source\repos\Get Followers\Twitter Console\Program.cs   60  Active

Just looking for someone to talk to about this and fill in the blanks for someone who's never coded before. Or better explanations on how to make this work. Tweetinvi is touted as the easiest way to do this, but if there is an easier/simpler way to make this happen please direct me there. If you can create something that does this for me to run and explain it I'd be willing to pay you for your time. (everything I've found that does this is a monthly recurring fee, and I still have to waste a lot of time clicking buttons to make it happen)

Thanks, Mark

MayakoAelys commented 6 years ago

Hello @ForDebating

I don't have the time right now to help you on the code side but if you want some help, you can try on StackOverflow with the tag "tweetinvi": https://stackoverflow.com/questions/tagged/tweetinvi

It's not really active though, even less than here but it worths the try

linvi commented 6 years ago

Hello there,

Sorry for not replying, as @MayakoLyyn was mentioning I have very limited of time to help at the moment to help you with your problem. Though I will have more time available after the 9th of July.

I will be looking into your issue at that time. In the meantime I would strongly suggest that you look into the documentation.

Cheers, Linvi