Captcha required youtube api C# - authentication

Every time I make a request for getting a video to youtube API I make something like that:
public Video GetVideo(string videoId)
{
YouTubeRequest request = new YouTubeRequest(settings);
Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + videoId);
return request.Retrieve<Video>(videoEntryUrl);
}
Sometimes I get an exception saying "Captcha required". I was wondering if building the YoutubeRequest is asking for an authentication token for every call to GetVideo and because of that I'm getting this exception. Is it possible? How can I avoid this exception? And I'm not talking about handling it with a try-catch.
Thanks!!

Yes; there are ways of reusing a ClientLogin token. Please see scenario 4 in this blog post, and take a look at the "Recalling an auth token" section of this document.
Better yet, I'd recommend making the move to OAuth 2 instead of ClientLogin, as mentioned in that blog post.

Related

How Do I Create a Custom Error Response in Zapier

I am creating a new App for our customers to use. However, I am having a hard time finding any documentation on properly responding with error codes back to Zapier in the event something goes wrong.
One example I have, is a new customer creates a Zap and when attempting to look up data from our API, we have no data to return to them just yet.
It took me a while, but using the 400 HTTP header got me a little closer. But in this example, you can see, I just get a basic text response back. I know I'm logged in as Admin, so it will look different. However, without a doubt, I'm sure I need to format the response Object, so Zapier can lay out my error text like the second example.
I am hoping to replicate what Google Sheets has done below and specify the response, so the user knows what the issue is.
you can do something like:
if (resp.status != 200) {
throw new z.errors.Error(`Something went wrong.`);
}
You can read further here

How do I use/read an api documentation to send a simple request?

I know this is probably strictly case-specific, but I do feel like I encounter this problem a lot so I will make an effort to try and understand it better.
I am new to using APIs, but I have never succeeded in using one without copying someone's code. In this case, I can't even find any examples on forums, nor in the API documentation.
I'm trying to pull my balance value from my investment bank "NordNet" to scroll, amongst other things, on an Arduino display I've made. Right now I use python Selenium to automatically but "physically" login to NordNet and grab my balance from the DOM. As I'm afraid I might get "punished" for such botted behavior, and because the script is fairly high maintenance (as the HTML changes over time), I would obviously much rather get this information through NordNet's new API.
Link to NordNets API doc
Every time I try to utilize an API doc it's always the same, it looks easy, but I can never get it to work.
This time I tried to just play a little with the API before exploring further.
I use PostMan to send the simplest request:
https://www.nordnet.se/api/2
And I get a successful code 200 JSON response.
I then try to take it a step further to access my account data using this endpoint:
https://www.nordnet.se/api/2/accounts
For this one, I obviously need some authentication of some sort
The doc looks like this:
So I set my PostMan client up like this and get the response showcased:
I've put my NordNet login into the "Auth" tab as "basic auth" and I then see PostMan encrypts this info some way, in the "Headers" tab.
I'm getting an unauthorized response code and I have no idea why. Am I using PostMan wrong (probably)? Is the API faulty (probably not)? There is a mention of a session_id that should contain both password and username? Maybe something completely else...
I hope you can help
The documentation says to use session_id as username and password for that api ,
so try logging in and then get the session id (try with both sid and ssid) . from network tab and pass it as username and password for authorization .
sid- is for http and ssid for https i guess , try with both

How to read the headers of the REST API response using TRON and Alamofire

I am currently using Xcode8 and have built an app that make REST API calls using TRON and Alamofire.
I am successfully calling the API and getting back a response. This response BODY is being parsed into a model class that is structured to mimic the response body of the API call, and all of my properties are being populated with the correct values.
The new requirement I have now been given is to read some authentication information from the HEADER of the response. This information has been defined as a JSON Web Token. I can't seem to find any information on how to parse this information from the response HEADER using TRON or Alamofire.
Any insight, example, links, or comments will be greatly appreciated. Thanks in advance for any help.
I found the answer on this SO post.
And then I solved it in my project like this:
if let authorization = response.response?.allHeaderFields["Authorization"] as? String {
UserDefaults.standard.set(authorization, forKey: Constant.AUTHORIZATION_TOKEN)
}

Google+ .Net API - Getting Authenticated and retrieving profile

I'm trying to get a users profile information for google+ via the .NET API but am having trouble.
Does anyone know if they have changed how the special ID "me" works?
In the documentation it says this can be used as a special ID to get the currently authenticated users information however this throws a 404 from both the API in my code and on Google's own test page https://developers.google.com/+/api/latest/people/get. I was logged in when trying this.
Does anyone know how to get the user ID as I would happily use that instead of me but it isn't returned after the user authenticates as far as I can see (just an authcode)?
I also tried using user IDs returned when using the standard .net Oauth stuff but it isn't the correct ID, I assume it is for something else.
As for my method of getting to this stage, I first downloaded the example files here: http://code.google.com/p/google-api-dotnet-client/wiki/GettingStarted
They don't have a plus example so I took the Tasks.ASP.NET.SimpleOAuth2 example and swapped out tasks (which worked fine) for the plus equivalent.
I also tried rolling this into my own project.
Neither worked. I get the user forwarded to Google where they give me access fine and then when I return they are authenticated successfully as far as I can see, however when I call service.People.Get("me") it returns a 404.
If anyone could help with the above questions (using me, or gettign the user ID) I would appreciate it.
To the moderator who closed the initial version of this question, I have tried to make this as direct a question as possible so please don't close it. This is a legitimate question I would really like help getting to he bottom of.
This is now out of date given recent platform updates. Although the plus.me scope still exists and this code will work, you should be using the plus.login scope for retrieving profile data in C#. For a great way to get started with retrieving and rendering profile information, please start from the Google+ C# quick start available here:
https://developers.google.com/+/quickstart/csharp
First off, the 'me' id still works and is unchanged. The way that it works is:
You authenticate the user using a standard OAUTH2 flow
You use the library to perform a People.get with the special value 'me'
The 404 error code is a little troubling, this means that the client isn't finding the endpoint. To debug this, you might want to use a packet sniffer like fiddler to see what the actual URL it's querying is.
Anyways, how about some C# code. The following example shows how to use the plus service to get the currently authenticated user (assuming you have authenticated someone). What's different from your snippet is that you need to form a get request for the API call, then run fetch on the get request. I've included the following example, for getting 'me', and the following code works:
var auth = CreateAuthenticator();
plusService = new PlusService(auth);
if (plusService != null)
{
PeopleResource.GetRequest prgr = plusService.People.Get("me");
Person me = prgr.Fetch();
}
All of the configuration of the server and getting a client working is pretty hard and pasting all of the code here would be less helpful than just giving you a sample.
And so... I have written a sample application that demonstrates how to do this and also includes a wrapper that makes it easier to develop using the Google+ API in C#. Grab it here:
Google+ C# Server-Side demo and library
Seems you need to use:
Person test = service.People.Get("me").Fetch();
and not
req = service.People.Get("me");
Person test = req.Fetch();
Even though they seem to be identical the first works and the second doesn't.
Still not sure why google's own page doesn't work though. Now to find out how to add things to the scope like birthday.

Graph Batch API

this is my first post at stackoverflow.
I am using the Facebook Graph Batch API to request the Feed-Updates from several users at once.
But I really don't know how the appropriate error handling is done. Following example should demonstrate my problem:
Batch request:
user1 - valid access_token
user2 - invalid (password change maybe?)
user3 - valid access_otken
The answer from Facebook could look like this:
successful answer
unsuccessful answer (OAuth Exception)
successful answer
But reading the docs, it seems like that the ordering of the answer is not guaranteed. So my question is, how do I connect the answers with their specific partial requests from the batch request?
Handling the OAuth exception is quite hard when you don't get the information to which request this exception belongs.
Any thoughts?
I'm not familiar with the PHP SDK, but on the Javascript SDK batching actually simulates the various calls themselves and returns an array of responses with header and body and such-like set.
You can then iterate through that looking for errors and responses.
I assume that the PHP SDK will use similar semantics.