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.
Related
I am developing a Facebook WPF application for my senior design project in college. I've never coded in C# or developed a WPF application before this. Right now I'm trying to implement logout functionality. I'm using a WebBrowser to do this, and the documentation seems to say that the method of doing this is to navigate to:
https://www.facebook.com/logout.php?next={redirectURI}&access_token={token}
in the browser, where the sections in curly braces are variables. For some reason, it brings me back to the Facebook home page (news feed) every time I do this. Is this due to a change made by Facebook in recent years or is there an error on my part? Alternative methods of logging out via a web browser, such as an alternative logout URL, would be appreciated as well.
With FB SDK V6, there are some nuances. I'll delve into a few things you need to verify in your code. Your code probably would've worked with previously, but today you should make the following changes, assuming you haven't already:
The redirectURI in your code needs to be changed to "http://www.facebook.com". Standard redirect URIs (including those associated with your access token generation) don't seem to work anymore.
You also need to make sure your redirectURI is an absolute URI. There is a very simple way to do this, which I will show in the code below.
Bringing it together, this code will work for the current FB C# SDK via a WebBrowser:
var fb = new FacebookClient();
var logoutURL = fb.GetLogoutUrl(new { access_token = {userAccessToken}, next = "https://www.facebook.com/"});
WebBrowser1.Navigate(logoutURL.AbsoluteUri);
A final note is that in my code, I chose to ask for the logoutURL instead of hardcoding it. It looks like after making the changes your logoutURL would still be correct, but it may be beneficial to retrieve the url to help ensure correctness. Good luck on your project.
I used Facebook SDK to connect with Graph API (get here: https://www.nuget.org/packages/Facebook/) and when received access _token I make a test with the account has 689 friends and it worked as well, but when I switch to another account has more than 3000 friends, it was got an exception and not return anything.
I has been researching for it and someone recommended me to use GetTaskSync() method in FacebookClient class, but I don't understand how to use this function (searched but got nothing).
Please help me, thanks in advance !
This Stackoverflow question describes using bundles to tell Facebook what upper limit to use for number of friends.
Use the Bundle object, call putInt("limit", 5000), then execute a GraphRequest using executeAsync.
https://stackoverflow.com/a/33409920/154186
I'm coming to .net web api from a JavaScript background, and I'm trying to make a proxy to help with a cross domain JSON request. I'm GETing from a server I don't control the source code for, so I can't configure CORS directly. Likewise, it doesn't speak JSONP.
So two questions as I try to get my head around Web API:
1) Is Httpclient the right tool for this job? (if not, what is?)
2) If httpclient IS the right tool, what is an absolute bare bones httpclient config so I can test this out? Not worried about throwing exceptions or anything else other than just GETing API data and feeding it to a jQuery client.
I guess one other piece of information that would be nice would be building username / password authentication into the http request.
Any help is much appreciated, as are links to any good blogs / tutorials / etc that might help as an introduction to this sort of thing. I've watched several today alone, and I'm still not able to get a basic http request going on the server side without resorting to cutting / pasting other people's code.
Thanks in advance!
** EDIT - To make this question a bit more clear, what I'm trying to test is 1) Can the proxy connect to the third party server, which involves authentication via a username and password 2) Can the proxy then respond to the jQuery client request with the JSON data it received from the third party server.
Thanks to all who have taken the time to respond.
HttpClient seems to be ok in this job.
About the minimal config- it depends on what the third party expects. In most cases would work out-of-the-box, but there always may be some minor tweaks like headers and/or auth code.
I have just found some blog entry where some author shows how to test such a proxy and shows the proxy code too. Please see: http://www.davidbreyer.com/programming/2014/10/11/create-fake-responses-to-rest-service-calls-in-c/
You can find info about sending credentials here: How to use credentials in HttpClient in c#?
HTH
EDIT:
this sample code should work (copied from blog above and modified):
public class Proxy
{
public async Task<ExampleDto> GetExample(int id)
{
var client=new HttpClient();
//set some auth here
//set other headers
var response = client.GetAsync(
string.Format("/api/restserviceexample/{0}", id))
.Result.Content.ReadAsAsync<ExampleDto>();
return await response;
}
}
It's so simple that you can just run it and see if the other server responds. If not, you can play with headers - since all the session info and user auth info are sent using ookies and/or headers, all you have to do is to see how it's made with regular browser and then fake it on the server. Probably best tool for this job will be Fiddler.
However - there is one thing to consider. If the other service has special method for authorization (other than passing credentials with each request) the whole thing becomes tricky, since your proxy should perform authorization using their service, then store their auth cookie on the server or propagate them to the browser and attach them with all next requests.
First, you don't need ASP.NET with C# if you really want minimal.
.NET has great http handling without ASP. Check out classes like HttpListener, HttpListenerContext, HttpListenerRequest, etc... Yes, you'll have to write some boilerplate as your application, but these classes are pretty good.
See among others:
http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=599978
Second, if you want user & password, I'd checkout using oauth authentication so you don't have to deal with them directly. Google Plus, Windows Live, Facebook, etc... all have similar OAuth 2.0 APIs for that. See among others:
http://msdn.microsoft.com/en-us/library/dn659750.aspx
https://developers.google.com/+/web/signin/server-side-flow
https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/v2.2
I'm just trying to make an yahoo boot that send to registered user of my application an instant message. I've spent some hours searching the web on how to do it but yahoo developer documentation sucks.First of all I don't know what servers I should use for authorization, log in, and messaging. I have a consumer key and I've tried to follow this steps but nothing works.
Any advice/suggestion is welcome.
The documentation looks to be very good, I think the issue here is that your knowledge of how REST API's work in general is a bit lacking.
Let's talk about diagram #2: Get a request token using: get_request_token.
get_request_token is part of an HTTP endpoint, and in their diagram they want you to pass in a handful of parameters to validate your request.
oauth_consumer_key
oauth_nonce
oauth_signature_method
etc
(If you need more clarification of any step you can find it in the tree view on the left hand side of the page)
The request URL:
https://api.login.yahoo.com/oauth/v2/get_request_token.
Now at this point you can either use the HTTP GET or POST verb. If you decide to use GET you will need to include those above parameters as a query string.
?oath_consumer_key=myConsumerKey&oauth_nonce=oathNonce etc
I will leave it to you to write the associated C# code. You'll want to start off with the HttpWebRequest.Create() method
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!");