Twitter C# search using solely TwitterSharp example - c#

I am currently trying to do a search from Twitter using C#.
I am new to C#, and after finding that I should use TweetSharp (https://stackoverflow.com/questions/27266419/twitter-api-1-1-with-net-3-5?noredirect=1&lq=1#=) and installing it with NuGet on VisualStudio, I struggle to make a simple authentification and search, as I did not find any simple example based solely on TweetSharp.
I already got my API key, API secret, access token and access token secret (on the Twitter dev website).
All I want is to get some JSON data after searching a hashtag.
Simple example code based on uniquely on TweetSharp (and no other libraries, especially ones not findable on NuGet) would save my life ! A documentation for TweetSharp might also do the trick, currently I did not find it...
Cheers,
Kevin

Following your first comment. Tweetinvi is a library that has been actively maintained for 4 years now as compared to Tweetsharp. It has been available on nuget since 2013 and has recently published its first major version 1.0.
To answer your question using Tweetinvi:
// Authentication
Auth.SetUserCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
// Get json directly
var tweetsJson = SearchJson.SearchTweets("hello");
// Get json from ITweet objects
var tweets = Search.SearchTweets("hello");
// JSON Convert from Newtonsoft available with Tweetinvi
var json = JsonConvert.SerializeObject(tweets.Select(x => x.TweetDTO));
var tweetDTOsFromJson = JsonConvert.DeserializeObject<ITweetDTO[]>(json, JsonPropertiesConverterRepository.Converters);
var tweetsFromJson = Tweet.GenerateTweetsFromDTO(tweetDTOsFromJson);

Related

Issue with Twitter API possibly Tweetinvi (Forbidden)

I've been trying for days on this and think that the issue is somewhere with my developer account but thought I'd ask for advice here first before digging in there.
I have followed the documentation and multiple tutorials and this should work it seems but no matter what call I make using Tweetinvi to Twitter I get "Forbidden" which when looking at the twitter codes means my authorization is correct but that I am asking for something that I don't have access to, but I am just trying to send a test tweet to see if the program works, which according to Twitter's documentation I should have full access to. Here's the code that I took from Tweetinvi's Tutorial on how to make a "Hello World" tweet but it just doesn't work cuz it returns "Forbidden".
static async Task Main(string[] args)
{
var userClient = new TwitterClient("APIKey", "sAPIKey", "AccessToken", "sAccessToken");
var tweet = await userClient.Tweets.PublishTweetAsync("This is a test tweet");
Console.WriteLine(tweet);
}
It's not just the send tweet function either, if I try to pull any information at all it says it's forbidden so I feel the issue is on Twitter side not my code but I am just trying to learn it as a hobby and have no idea. Just was told Tweetinvi would make everything take 5 minutes and now I am at three days of trying to figure this out. Any help in figuring this out would be nice and greatly appreciated.
Twitter's latest API release [Nov 15th 2021] has an entry level of access called "Essential" that provides access to the v2 API, because this should be the base for most new apps. If you need access to v2 and also to the legacy v1.1 APIs in the same app, you will need "Elevated" access, which is also available for free. The PublishTweetAsync method you are calling in the code in this question is trying to hit the v1.1 Tweet statuses/update endpoint, so your app will need Elevated access in order to make it work.

Microsoft Graph Client SDK vs. Requesting JSONs

I know that the query:
https://graph.microsoft.com/v1.0/me/messages
Corresponds to:
GraphClient.Me.Messages.Request().GetAsync()
I am trying to replicate the following requests in Microsoft Graph Client SDK :
Get All Categories
https://graph.microsoft.com/beta/me/outlook/masterCategories
Corresponding Graph client query: ??
Get All messages that contain certain words in their subject
The link will be similar to this
https://graph.microsoft.com/v1.0/me/messages?$search="hello world"
Corresponding Graph Client : ??
Update each of these messages with a category
?
The documentation only gives 2 examples, where could i find a list of examples/reading material on this?
The SDK is generated for the production endpoint (v1.0), so you will have to make a custom request for beta APIs
List<QueryOption> options = new List<QueryOption>
{
new QueryOption("$search", "hello world")
};
var filteredMessages = await
graphClient.Me.Messages.Request(options).GetAsync();
This also requires using custom requests since this is beta functionality.
We appreciate your feedback about our docs and how to use the SDK. We have some additional reference in the repo and are continuing to examine options for improving our SDK docs.
Since I don't have enough reputation points, I had to post an answer instead of a comment.
Thanks user8608110 for your help. Unfortunately, I can't use graph explorer because I'm not an admin. I think I have my patch request setup correctly, but I keep getting an "Empty Payload" error.
I thought stackoverflow was for us to help each other not delete the post of people trying to get help.

Google Freebase Api C# .Net Example

I am new to developing with the Goolge API’s. I am trying to get the Google.Apis.Freebase.V1 API working in C#. Does anyone have a small example on using this API in C#? I have spent the last several days looking and can only find a couple of examples for the old Freebase Api. Nothing for the Google API.
I am just looking for a simple example on setting up a connection to the API, doing a search, then how to handle a MQL query back into a Json object. The simpler the better.
Thanks
Scott
The correct code to do a MQL query in C# using the Google API Client Library should look something like this:
string API_KEY = "your-api-key-here";
FreebaseService service = new FreebaseService{ Key = API_KEY };
String query = "[{\"id\":null,\"name\":null,\"type\":\"/astronomy/planet\"}]";
FreebaseService.MqlreadRequest request = service.Mqlread(query);
string response = request.Fetch();
Console.WriteLine (response);
Unfortunately, there seems to be some sort of error with the client library right now as its not returning any results. I'll try to figure out what's going on there.
Update: The problem appears to be that the client library passes along an alt=json parameter which the Freebase API is unable to support. The Python client library has a way to disable this but there no way to do it in .Net. You can follow the open bug for this on the Google Code project.

Tweet An Update Using C# TweetSharp With New OAuth

I don't suppose anyone has used the latest version of TweetSharp to do a twitter status update, I was using the old version and now getting a bit lost with this OAuth stuff and cannot get it to work.
I'd just like some example code of using it to do a simple status update?
This URL will provide the example you need to get your head around OAuth: http://tweetsharp.codeplex.com/wikipage?title=UserGuide&referringTitle=Documentation
From there, there's a method on TwitterService called SendTweet which should be fairly straightforward. Once you have an access token, you can do it like this:
var service = new TwitterService(_consumerKey, _consumerSecret);
service.AuthenticateWith(_accessToken, _accessTokenSecret);
service.SendTweet("I'm totally tweeting!");

What are the available functions to send notifications to a Facebook user?

Currently I am using Codeplex's Facebook Developer Toolkit version 2 for my ASP.net Facebook application. I would like to be able to send notifications to a user's Inbox or wall of the application and was wondering what are the available functions to do that? If not in the API, then please provide example functions from the main Facebook library. This will help immensely. Thanks!
After a brief search I found an example of sending notifications using the toolkit:
facebook.Components.FacebookService fs
= new facebook.Components.FacebookService();
fs.ApplicationKey =
ConfigurationManager.AppSettings["APIKey"];
fs.Secret =
ConfigurationManager.AppSettings["Secret"];
string sessionKey =
dict["facebook_session_key"];
fs.SessionKey = sessionKey; fs.uid =
long.Parse(member.FacebookId);
fs.notifications.send(member.FacebookId,
"notification message");
(from: http://facebooktoolkit.codeplex.com/Thread/View.aspx?ThreadId=49876)
After looking through the Codeplex source it's clear that this sends a user-to-user notification, and therefore requires an active user session of the sender.
Codeplex does not appear to support app-to-user notifications which do not require a session, but adding this feature would be trivial. Add a type variable to the send method and set it accordingly based on the API documentation here: http://wiki.developers.facebook.com/index.php/Notifications.send
The source code for the notifications.send method in the Codeplex Developer Toolkit is here:
http://facebooktoolkit.codeplex.com/SourceControl/changeset/view/28656#233852
Please keep in mind that the Codeplex developer toolkit source code has not been updated in over 3 months. This means that it does not support many new Facebook API features and changes. You may want to browse the client library wiki page to find a library that is more up to date: http://wiki.developers.facebook.com/index.php/Client_Libraries

Categories