Authenticate Node app to download captions via YouTube Data API - oauth-2.0

I'm writing a Node application to get captions for videos from a YouTube channel.
I've downloaded credentials, got the YouTube Node quickstart sample working and successfully added code to get a list of captions for a single video ID:
service.captions.list(parameters, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
for (const item of response.data.items) {
console.log(item.id);
// service.captions.download({id: item.id});
}
});
However, if I uncomment the line to download captions, I get a 'Login Required' error.
How do I log in, or run code to log in?

Related

Unable to log in Dailymotion user using JS SDK

I have a React app from which I want to upload videos to the account of the logged in user. I have successfully done this retrieving tokens manually and calling the API but can't find a way to log in using the JS SDK in my React app.
I present the user with a button for log in:
e.preventDefault()
window.DM.login(
function (response) {
if (response.session) {
// user successfully logged in
console.log(response)
} else {
// user cancelled login
console.log(response)
}
},
{
client_id: my_id,
scope: "read write",
response_type: "code"
}
)
}
The login popup appears, I log in and get sent to the callback url. However, refreshing the original site, or the callback popup, still shows as no session and without login. I check with:
status === 'ready' &&
window.DM.getLoginStatus(function (response) {
if (response.session) {
// logged in and connected user, someone you know
console.log(response)
} else {
// no user session available, someone you dont know
console.log(response)
}
})
})
and I always get { status: "unknown", session: null }
Loading the SDK is handled with a hook const status = useScript('https://api.dmcdn.net/all.js')
Do I need to handle something manually from the callback page? Isn't the SDK supposed to handle it in the background? I would appreciate some insights on what I might be doing wrong.
Thanks.
As always, I spent hours trying to find a solution and, as soon as I post, I find it:
Client_id and response_type must not be passed in DM.login.
Instead, you have to pass the API key in DM.Init, like so:
useEffect(() => {
status === 'ready' &&
window.DM.init({
apiKey: '123456789',
status: true, // check login status
cookie: true // enable cookies to allow the server to access the session
});
})
This brings up the popup and after inputting the credentials the SDK correctly detects the session, closing the popup and authing the user.

YouTube - Data API v3 Unable to display private videos of my YouTube channel on my website using Google Service Account

I have few private videos on my YouTube channel and i want to put them on my website. Basically i don't want my website users to watch them directly on my YouTube channel. Furthermore i don't want to show consent screen to the users either. I browsed and found this example at stackoverflow in which DalmTo is suggesting someone to use Google Service Account to achieve this. My code works fine with publicly available videos but it does not show the private videos whenever i search the video with it's ID.
Here's my code:
<?php
session_start();
require_once('vendor/autoload.php');
$client = new Google_Client();
$client->setApplicationName("YouTube-Example");
$client->setScopes('https://www.googleapis.com/auth/youtube');
putenv("GOOGLE_APPLICATION_CREDENTIALS=service_account.json");
$client->useApplicationDefaultCredentials();
$youtube = new Google_Service_YouTube($client);
try{
$response = $youtube->videos->listVideos(
'snippet',
array(
'id' => 'pW0og1OZurE' //private video unable to display
));
echo "<pre>";
print_r($response);
} catch (Google_Service_Exception $e) {
$htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
} catch (Google_Exception $e) {
$htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
}
?>
I followed the documentation but i can't figure out why it's not working. Please help me out.
Thanks in advance.
Here may be your answer:
The forMine parameter indicates that the response should only search within the authorized user's videos. Also, since this request uses the forMine parameter, it must also set the type parameter value to video.
If you have not uploaded any videos associated with that term, you will not see any items in the API response list.
Source: Google developers docs
Displaying of private videos is not allowed in Youtube API as stated in the help guide.
Private videos can only be seen by people who have been invited to
view the video.
Here are some possible reasons why you or somebody you’ve shared the
video with aren’t able to see a private video:
-Viewers need to have a YouTube account and be signed into it when trying to view the video.
-If the viewer has multiple YouTube accounts, they must be signed into the account which the video has been shared with.
-Since private videos don’t appear on a Channel page, the person will need to use the specific link to the private video. YouTube will send
them an email with the link once you’ve invited them, but you can also
send it yourself.

Appcelerator login API getting error in response Unexpected identifier

I am using Appcelerator iCloud·Cloud.Users.login·API its callback is giving me following response:
{"success":false,"error":true,"message":"JSON Parse error: Unexpected identifier \"An\""}
I am stuck on the things and not able to move forward, Our live App users on App Store are also affected from this.
Problem comes when we open Appcelerator Titanium project from Xcode and build the app from there and run on iOS simulator or device.
Here is the code which I am using:
Cloud.Users.login({
login : userId,
password : password,
}, function(e) {
//alert(e);
Ti.API.info("In success ....Cloud.Users.login..");
Ti.API.info('response from login service'+JSON.stringify(e));
if (e.success) {
Ti.API.info('User successfully login');
} else if (e.error) {
Ti.API.info(e.message);
_activityIndicator.hide();
alertWin.close();
}
//button.show();
});
In my case its going in else part because of response which I provided "success":false in the JSON which I am getting in callback function from Appcelerator cloud API.
Help me to resolve this error I am getting in callback.

How to check if a YouTube channel is active

It looks regardless of whether a channel has been created by a user, the youtube api will return a channel for that particular user.
Java API
YouTube.Channels.List search = youTube.get().channels().list("id);
search.setPart("id");
ChannelListResponse res = search.execute();
List<Channel> searchResultList = search.getItems()
Channel channel = searchResultList.get(0); // there is always a channel
For the authenticated user, the channel seems to exist but when going to the YouTube profile, it states "You must create a channel to upload videos. Create a channel" or if going to the url without the user being authenticated, it'll say "This channel is not available at the moment. Please try again later."
How do check that a youtube channel is active or not. do i have to attempt to upload to it?
There are two ways to do this:
When you make an API call such as playlist management or video uploading, if there is no linked channel, the API will throw a GoogleJsonResponseException. Here's a code snippet showing you what happens when you try to make a playlist update API call and there's no channel:
try {
yt.playlistItems().insert("snippet,contentDetails", playlistItem).execute();
} catch (GoogleJsonResponseException e) {
GoogleJsonError error = e.getDetails();
for(GoogleJsonError.ErrorInfo errorInfo : error.getErrors()) {
if(errorInfo.getReason().equals("youtubeSignupRequired")) {
// Ask the user to create a channel and link their profile
}
}
}
You'll want to do something when you get "youtubeSignupRequired" as the reason for the error.
The other way is to check ahead of time. Make a Channel.List call and check for "items/status". You're looking for the boolean value "isLinked" to equal "true". Note that I've inserted a cast in this sample code because in the version of this sample, the client was returning a String value instead of a typed Boolean:
YouTube.Channels.List channelRequest = youtube.channels().list("status");
channelRequest.setMine("true");
channelRequest.setFields("items/status");
ChannelListResponse channelResult = channelRequest.execute();
List<Channel> channelsList = channelResult.getItems();
for (Channel channel : channelsList) {
Map<String, Object> status = (Map<String, Object>) channel.get("status");
if (true == (Boolean) status.get("isLinked")) {
// Channel is linked to a Google Account
} else {
// Channel is NOT linked to a Google Account
}
}

Using the Youtube Data API and the AP crashed

I have downloaded the sample code of the below path
http://www.codeproject.com/Articles/143669/Manage-YouTube-using-C-and-Youtube-API-1-6
Then I have installed the YouTube_SDK_2.1.0.0.msi
Now I can build the project successfully, but when I want to search a video in the Youtube
the AtomFeed of the videofeed will return the Error=NoLinkedYouTubeAccount
Please tell me what happened, I already surveyed some days in network.
Sample code list as below
yousettings = new YouTubeRequestSettings("My AP", devkey, username, password);
yousettings.Credentials.AccountType = "GOOGLE";
.........
videofeed = yourequest.Get<Video>(new Uri(feedUrl));
videofeed will always return fail then the Sample Ap will be crashed, the crash info list as below:
An unhandled exception of type
Google.GData.Client.GDataRequestException occurred in
Google.GData.Client.dll Additional information: Execution of request
failed:
http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?time=today
Note:
I have link the Youtube account to the Google account.
I try to modify the yousettings.Credentials.AccountType = "GOOGLE";
FeedUri = "http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?time=today"

Resources