linvi / tweetinvi Goto Github PK
View Code? Open in Web Editor NEWTweetinvi, an intuitive Twitter C# library for the REST and Stream API. It supports .NET, .NETCore, UAP (Xamarin)...
License: MIT License
Tweetinvi, an intuitive Twitter C# library for the REST and Stream API. It supports .NET, .NETCore, UAP (Xamarin)...
License: MIT License
Hi, I'm constantly getting 403 with "This code is used when requests are being denied due to update limits". On the java forums, folks say you require ssl everywhere and that's what fixed the error. Any thoughts? I'm using 0.9.7.1
i read your documentation about authorization, but my instagram app does not have nether pin nor url based authentication, i think it should a sample like this section
Part 3 - Publishing the Statuses
https://www.develop.com/twitternetapps
your lib does not support this method or i do not find it in documentations
Simplify the development by unifying the namespaces of concrete class and interfaces for Parameters.
I am tweeting with the video.
Here is the code:
public static void Tweet_PublishTweetWithVideo()
{
string filePath = @"C:\Downloads\Video\1.mp4";
byte[] file1 = File.ReadAllBytes(filePath);
var tweet = Tweet.PublishTweetWithVideo("first tweet with video", file1);
}
How ever this gives me an error: on debugging I found this function returns null.
I get an error: " throw new OperationCanceledException("The tweet cannot be published as some of the medias could not be published!");"
public IMedia ChunkUploadBinary(byte[] binary, string mediaType)
{
var uploader = CreateChunkedUploader();
if (uploader.Init(mediaType, binary.Length))
{
if (uploader.Append(binary))
{
return uploader.Complete();
}
}
return null;
}
Has some one tried and found a solution to this problem? Please help!
I m using the latest build from Nuget :0.9.9.6.
It's maybe a problem with the Credentials process. It was working with versions before Tweetinvi 0.9.9.x
The first tweet is well posted but i ve got an error and the second one :
Object reference not set to an instance of an object on :
var media = Upload.UploadImage(imageBytes);
public class TwitterList
{
public double longitude { get; set; }
public double latitude { get; set; }
public string Message { get; set; }
}
public async Task PostAlert(double longitude, double latitude, string Message)
{
List<TwitterList> AlertList = new List<TwitterList>();
AlertList.Add(new TwitterList { latitude = 37.386052, longitude = -122.083851, Message = "Test message 1 : " + DateTime.Now });
AlertList.Add(new TwitterList { latitude = 42.386052, longitude = -122.083851, Message = "Test message 1 : " + DateTime.Now });
foreach (var item in AlertList)
{
await PostTwitterAlert(item.longitude, item.latitude, item.Message);
Response.Write(item.Message + "<br/>");
}
}
public async Task PostTwitterAlert(double longitude, double latitude, string Message)
{
try
{
var webClient = new WebClient();
string GoogleUrl = "http://maps.google.com/maps/api/staticmap?center=" + latitude.ToString() + "," + longitude.ToString() + "&zoom=7&markers=label:E|" + latitude.ToString() + "," + longitude.ToString() + "&size=500x400&sensor=true";
byte[] imageBytes = webClient.DownloadData(new Uri(GoogleUrl));
var credentials = new TwitterCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
var media = Upload.UploadImage(imageBytes);
Coordinates Coordinates = new Coordinates(longitude, latitude);
var tweet2 = Auth.ExecuteOperationWithCredentials(credentials, () =>
{
return Tweet.PublishTweet(Message, new PublishTweetOptionalParameters
{
Coordinates = Coordinates,
Medias = new List<IMedia> { media }
});
});
}
catch (WebException e)
{
var exceptionStatusCode = Tweetinvi.ExceptionHandler.GetLastException().StatusCode;
var exceptionDescription = Tweetinvi.ExceptionHandler.GetLastException().TwitterDescription;
var exceptionDetails = Tweetinvi.ExceptionHandler.GetLastException().TwitterExceptionInfos.First().Message;
Response.Write(exceptionDetails);
}
}
my code
var tweetToReplyTo = Tweet.GetTweet(631794399131881472);
var tweet = Tweet.PublishTweet("We love you back!", new PublishTweetOptionalParameters
{
InReplyToTweetId = tweetToReplyTo.Id
});
using System;
using Tweetinvi;
using Tweetinvi.Core.Credentials;
namespace TweetTry
{
class Program
{
static void Main(string[] args)
{
applicationMenu ();
}
static void applicationMenu()
{
ITwitterCredentials credentials = Auth.SetUserCredentials (Consumer Key, ConsumerSecret, AccessToken, AccessTokenSecret);
Console.WriteLine ("Select an action");
Console.WriteLine ("1. Tweet\n2. Get Timeline\n3. Get Logged User");
string input = Console.ReadLine ();
try
{
if (input == "1")
{
Tweet.PublishTweet ("@1o1reasons Thanks for the info");
Console.WriteLine ("Done");
}
else if (input == "2")
{
var tweets = Timeline.GetHomeTimeline();
Console.WriteLine (tweets.ToString());
}
else
{
var loggedUser = User.GetLoggedUser(credentials);
Console.WriteLine (loggedUser.ToString ());
}
Console.ReadLine ();
}
catch (Exception ex)
{
Console.WriteLine (ex.Message);
Console.ReadLine ();
}
}
}
}
Hi,
I've been trying to post a Tweet with an image but it hungs in this line:
Class:HttpClientWebHelper
Method: return await client.PostAsync(twitterQuery.QueryURL, httpContent);
This only happens when I called it from a site. If I used it in a Console application, like in your examples, it sucessfully post the tweet with the media.
Thanks you in advance.
If i use coordinates
var France = new Coordinates(48.869702, 2.342528);
var tweet = Tweet.PublishTweet("Some love from France!", new PublishTweetOptionalParameters
{
Coordinates = France
});
tweet = null
without coordinates all works
How can one retrieve more than 5000 follower ids? I have many users that have 20K
Naming convention (codeplex : https://tweetinvi.codeplex.com/workitem/2640)
Again request Twitter developers to get access to advance permissions to test this authentication mechanism.
Hey Linvi,
Is it possible to provide signed binaries?
Hi Linvi,
Twitter has added a new "dm_text_character_limit" field to help/configuration (added in the build up to increasing the Direct Message size limit, see #46).
Can this be exposed through Tweetinvi?
Cheers,
Josh
As reported on codeplex: https://tweetinvi.codeplex.com/workitem/2649
I am receiving tweets from the User Stream:
var stream = Stream.CreateUserStream();
stream.TweetCreatedByAnyoneButMe += OnTweetCreated;
await stream.StartStreamAsync();
The event handler processes the tweet then attempts to send a reply back to the user:
private async static void OnTweetCreated(object sender, TweetReceivedEventArgs e)
{
// Do something with the tweet
Tweet.PublishTweetInReplyTo("Thanks for your request!", e.Tweet);
}
Unfortunately, it would appear that the reply is simply just a new tweet, and is not attached to the original tweet in the timeline.
See attached screenshot showing reply as new tweet rather than actual reply.
Hello,
I am taking some time off for the summer holidays. During this time I won't be able to fix any bug (critical or minor), provide any help or advice. I will try to take a look to the page as soon as I will have an internet connection. In meantime please consider the following schedule:
Please do no be shy to post any issue, suggestion... I will review all of them when I get back.
Cheers,
Linvi
"Se" for Sweden
"jp" for Japanese
Unknown Language Codes
"ck", "xx"
Bug opened in codeplex (https://tweetinvi.codeplex.com/workitem/2637).
In addition to static methods, we want the models to provide additional information on the content that a classical developer have access to.
See if the issue can be fixed now that we are using HttpClient.
I am looking at the documentation for TwitterCredentials here:
https://github.com/linvi/tweetinvi/wiki/Authentication
Specifically, this LOC:
var appCredentials = new TwitterCredentials("CONSUMER_KEY", "CONSUMER_SECRET");
The problem is that I only see this in object explorer
Tweetinvi.TwitterCredentials.TwitterCredentials()
And
Tweetinvi.TwitterCredentials.SetCredentials(string, string, string, string)
Is the documentation out of date?
Thanks
Methods Search.SearchUsers, after first call, very often fails, with a System.NullReferenceException.
Hi Linvi,
Twitter has (relatively) recently upped the limit on the length of Direct Messages from 140 chars to 10,000.
For compatibility, the REST API limits messages to 140 chars unless you specify you want to use the new higher limit by adding "full_text=true" as a query param.
Could this functionality be added to Tweetinvi?
You can see the full details at https://twittercommunity.com/t/removing-the-140-character-limit-from-direct-messages/41348
Apologies if I've missed something and this is already implemented.
Cheers,
Josh
Add a solution showing how to publish/delete tweets.
https://tweetinvi.codeplex.com/workitem/2629
After a pause the EOF exception is often raised.
I'm using Visual Studio Express 2013 on a Windows 10 machine.
To replicate:
Create an default WP8.1 app or a Universal app.
Add Tweetinvi to WP project using NuGet package manager.
Add this code:
Auth.SetUserCredentials("", "", "", "");
var fs = Tweetinvi.Stream.CreateSampleStream();
fs.TweetReceived +=
(sender, args) =>
{
Debug.WriteLine("Tweet Received");
};
fs.StartStream();
This only returns 0-1 tweets and after a few minutes the StreamStopped callback is called with the exception:
Autofac.Core.DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Tweetinvi.Logic.TwitterQuery' can be invoked with the available services and parameters:
Cannot resolve parameter 'System.String queryURL' of constructor 'Void .ctor(System.String, Tweetinvi.Core.Enum.HttpMethod)'.
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Execute()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Activators.Reflection.AutowiringParameter.<>c__DisplayClass2.<CanSupplyValue>b__0()
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Execute()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.ResolveOperation.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable`1 parameters)
at Tweetinvi.Injectinvi.AutofacThreadContainer.Resolve[T](IConstructorNamedParameter[] parameters)
at Tweetinvi.Injectinvi.AutofacContainer.Resolve[T](IConstructorNamedParameter[] parameters)
at Tweetinvi.Core.Injectinvi.Factory`1.Create(IConstructorNamedParameter[] parameters)
at Tweetinvi.Streams.StreamTask.GetJsonResponseFromReader()
at Tweetinvi.Streams.StreamTask.Start()
The exact same code works fine in ordinary Windows 8.1 apps. I haven't tried yet with VS 2015.
Might be related to:
https://tweetinvi.codeplex.com/workitem/2619
I get a lot of successful publishes when calling PublishTweet or PublishTweetWithMedia, but when checking for an exception afterwards like so:
if (ExceptionHandler.GetLastException() != null)
var exceptionDescription = ExceptionHandler.GetLastException().TwitterDescription;
I get "Bad Request - The request was invalid or cannot be otherwise served. An accompanying error message will explain further. In API v1.1, requests without authentication are considered invalid and will yield this response."
I can see I'm passing the twitter token and secret key and some posts return no error and some do. What would make some posts go through and some not?
Hey,
Try out this little code snippet:
Auth.SetUserCredentials("xxxxxx", "xxxxxx", "xxxxxx", "xxxxxx");
var z = Tweetinvi.User.GetUsersFromIds(new List<long> { 1, 2, 3 }); // or any twitter Id's that do not exist
This will error yielding the following:
Value cannot be null.
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at Tweetinvi.Factories.User.UserFactoryQueryExecutor.GetUsersDTOFromIds(IEnumerable`1 userIds)
at Tweetinvi.Factories.User.UserFactory.GetUsersFromIds(IEnumerable`1 userIds)
at Tweetinvi.User.GetUsersFromIds(IEnumerable`1 userIds)
If you put a twitter id that is known to exist with the other Id's that are known to NOT exist:
Auth.SetUserCredentials("xxxxxx", "xxxxxx", "xxxxxx", "xxxxxx");
var z = Tweetinvi.User.GetUsersFromIds(new List<long> { 783214, 1, 2, 3 });
... everything works as expected.
Static classes are already quite big. Doing so will reduce the number of methods and instead users will now be able to new up parameters.
This is a breaking change that needs to be done for version 1.0.
I have an image to tweet and the tweet text contains a URL.
I shorten the url using google url shortener before I add it to the tweet text.
The total length of the tweet text with the shortened URL in it is 131.
Tried both PublishTweetWithImage and publish with optional paramters (Medias) both fail to publish.
If I simply remove the URL from the tweet text, the tweet succeeds and the image is published.
If I remove the image and publish just the text with the URL, the tweet succeeds.
It is only when a URL exists in the text of the tweet AND you try to publish with image that the tweet fails.
Note: failure is always indicated in the returned ITweet by:
'((Tweetinvi.Logic.Tweet)response).PublishedTweetLength' threw an exception of type 'System.InvalidOperationException'
Note also that I use TweetLength to verify that the tweet text is 131 just prior to the publish operation. IOW: the url has already been shortened and the total text including the shortened URL is 131
All variations of uploading a video (video size is less than 500kb) appear to hang when calling "Append". This includes:
// 1
var media = Upload.UploadVideo(video);
// 2
var uploader = Upload.CreateChunkedUploader();
var initSucceeded = uploader.Init("video/mp4", video.Length);
var success1 = uploader.Append(video);
var media = uploader.Complete();
// 3
var twit = Tweet.PublishTweetWithVideo(tweet, video);
The line uploader.Append(video);
hangs, all other methods never return.
Upon inspection by Fiddler, the Twitter API is returning perfectly fine with a HTTP 204 status code, and looking into the code (only on Github, sorry I haven't had the chance to download and debug further) I can't see any obvious reason why this would cause an issue.
Hey Linvi,
Can I log in as an application and use 450 queries instead of 180?
Twitter Client Handler Contains, update Tweetinvi.Builder.ps1 to automatically update this information :
request.Headers.Add("User-Agent", "Tweetinvi/0.9.10.x");
I'm doing something wrong?
public ActionResult About()
{
String UrlContexto = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath;
// Store the application-only credentials into a variable
var applicationCredentials = CredentialsCreator.GenerateApplicationCredentials(_consumerKey, _consumerSecret);
String callBack = UrlContexto + Url.Action("Contact", "Home");
// Get the URL that the user needs to visit to accept your application
var url = CredentialsCreator.GetAuthorizationURLForCallback(applicationCredentials, callBack);
if (url != null)
{
return new RedirectResult(url);
}
else {
return View();
}
}
public ActionResult Contact(string oauth_token, string oauth_verifier)
{
TwitterCredentials.SetCredentials(oauth_token, oauth_verifier, _consumerKey, _consumerSecret);
Tweet.PublishTweet("Hello Wolrd Again!");
return View();
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.