GTLQueryYouTube:queryForVideosListWithIdentifier:part: didn't do anything (Objective C ) - ios

I'm trying to use the iOS-GTLYouTube library for displaying videos. So far this is what I've got:
//Get the youtube video list
GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
// Set the APIKey
service.APIKey = #"APIKey";
GTLQueryYouTube *query = [GTLQueryYouTube queryForVideosListWithIdentifier:[vidListIds copy] part:#"id,snippet"];
GTLServiceTicket *ticket = [ service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error)
{
// This callback block is run when the fetch completes
if (error == nil)
{
GTLYouTubeVideoListResponse *products = object;
// iteration of items and subscript access to items.
for (GTLYouTubeVideo *item in products)
{
GTLYouTubeVideoSnippetThumbnails *thumbnails = item.snippet.thumbnails;
[thumbnailMutableList addObject:thumbnails];
NSLog(#"Title: %#", item.snippet.title);
}
}
else
{
NSLog(#"Error: %#", error.description);
}
}];
I don't know why but this code didn't seem to do anything. There's neither the "Title:" log nor the "Error" log. I know that it was done in a separate thread so it worked asynchronously. But I've waited for 1-2 minutes and still nothing is shown. Can anybody help me here? Thanks.

Never mind. In the NSMutableString *vidListIds I forgot to append a comma. Silly me. Thanks for reading though. Sorry for the false alarm. :)

Related

Parse- [query findObjectsInBackgroundWithBlock:^.)]; Block Doesn't execute w/ Action Extension

I'm trying to develop and Action Extension for iOS9.1 that is supposed to query Parse for some data.
I've added, enabled and tested Parse in the extension and I'm successful at creating test objects and checking for current user.
I can not get the code inside Parse's query method
[query findObjectsInBackgroundWithBlock:^ to execute. LLDB just keeps skipping it so I'm really at a loss.
This code executes perfectly within the container app so I'm a bit confused.
- (void)viewDidLoad
{
[super viewDidLoad];
[Parse enableLocalDatastore];
[Parse enableDataSharingWithApplicationGroupIdentifier:#"group.com.app.slinky"
containingApplication:#"com.app.Slinky"];
[Parse setApplicationId:#"xxxxx"
clientKey:#"xxxxx"];
for (NSExtensionItem *item in self.extensionContext.inputItems) {
for (NSItemProvider *itemProvider in item.attachments) {
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypePropertyList]) {
[itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypePropertyList options:nil completionHandler:^(NSDictionary *jsDict, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
NSDictionary *jsPreprocessingResults = jsDict[NSExtensionJavaScriptPreprocessingResultsKey];
NSString *pageTitle = jsPreprocessingResults[#"title"];
NSString *pageURL = jsPreprocessingResults[#"URL"];
if ([pageURL length] > 0) {
self.siteURL.text = pageURL;
self.URLstring = pageURL;
}
if ([pageTitle length] > 0) {
self.siteTitle.text = pageTitle;
}
});
}];
break;
}
}
}
[self queryParse];
}
-(void)queryParse{
PFQuery *query = [self.friendsRelation query];
[query orderByAscending:#"username"];
**[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
NSLog(#"%# %#", error, [error userInfo]);
} else {
self.friends = objects;
[self.tableView reloadData];
}
}];**
}
There are some limit to fetch Objects from Parse. Read Here
One has a limit of obtaining 100 objects, but anything from 1 to 1000 has a valid limit.
You have to set the limit again for the query for next objects and skip the properties of PFQuery.
You will have to query again and again until you reach the total count.
For Example - If you have 3000 objects to be fetched, then you have to query 3 times with a count of say 1000.
OR
Call [self queryParse]; inside dispatch_async(dispatch_get_main_queue(), ^{ }); block.
Hope this might workout.
This was just a result of a 12 hour refractoring marathon :-(
When I moved the queryParse call into its own method. I lost the definition of
self.friendsRelation = [[PFUser currentUser] objectForKey:#"friendsRelation"];
essentially sending a bad query... I don't know why it isn't return an error but regardless I can check that off now.
Thank you all for you help!

google drive iOS sdk, can't get file's description field

In my application, I need to get file's description, however, the descriptionProperty was always nil for every file I've got. I did the same thing using google API explorer (the field was the same: items(description, title)), and could get the description successfully.
The code is the following:
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.fields = #"items(description,title)";
[driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLDriveFileList *files, NSError *error) {
if (error == nil) {
NSLog(#"has %d files", [files.items count]);
GTLDriveFile *item;
for (int i = 0; i < files.items.count; i ++) {
item = [files.items objectAtIndex: i];
NSLog(#"%#", item.title);
NSLog(#"%#", item.descriptionProperty);
}
} else {
NSLog(#"An error occurred: %#", error);
}
}];
the log message I've got:
has 19 files
TestFile.txt
(null)
TestFile1.txt
(null)
...
As you can see, I got the title successfully, but the description was null for every file. I also tried not to set query.fields to let it get all fields. In this case, I could successfully get the description. But I really don't want to get all fields cause it's not necessary at all. Does anyone know what caused the problem? Thanks a lot!
Thanks for the report, this is a bug that should be fixed this week.

YouTube Objective-C API video maxResults

I would like to know the best way to get passed the video maxResults. I can't set it past 50. I need to get about 207 videos right now. This list will continue to grow over time.
Do you have any suggestions on how I would do this?
GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
service.APIKey = #"API Key";
service.shouldFetchInBackground = YES;
GTLQueryYouTube *query = [GTLQueryYouTube queryForPlaylistItemsListWithPart:#"snippet,contentDetails"];
query.playlistId = #"Playlist ID";
query.maxResults = 50;
GTLServiceTicket *ticket = [service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
// This callback block is run when the fetch completes
if (error == nil)
{
GTLYouTubeSearchListResponse *products = object;
GTLYouTubePlaylistItemListResponse *playlistItems = object;
for (GTLYouTubeSearchResult *item in products)
{
GTLYouTubeThumbnailDetails *thumbnails = item.snippet.thumbnails;
GTLYouTubeThumbnail *thumbnail = thumbnails.high;
NSString *thumbnailString = thumbnail.url;
if (thumbnailString != nil)
{
[self.thumbnailsURL addObject:thumbnailString];
[self.thumbnailsArray addObject:thumbnailString];
[self.thumbnailImages addObject:#"120x120#2x.png"];
[self.thumbnailTitleArray addObject:item.snippet.title];
}
}
for (GTLYouTubePlaylistItem *playlistItem in playlistItems)
{
GTLYouTubePlaylistItemContentDetails *details = playlistItem.contentDetails;
[self.videos addObject:details.videoId];
}
}
else
{
NSLog(#"Error: %#", error.description);
}
self.loading.hidden = YES;
[self.tableView reloadData];
}];
Thank you in advance for your time! :D
You'll get the rest of the results with using paging.
YouTube API supports pagination. You need to put your nextPageToken in your next request as pageToken to get the next page(50 in your case) of results.
These 2 answers of mine should help you:
page tokens use youtube api v3
Retrieve all videos from youtube playlist using youtube v3 API

Objective-C YouTube API - creating video object from URL

I am given a list of youtube IDs. For each of this IDS, I want to use the YouTube API to get the title, duration, and thumbnail. I then want the user to be able to click these thumbnails which takes them to a UIWebView where they can watch the video.
I'm really stuck on how I can actually create a video object from the ID. I dont really understand the process in given in Google's sample code, they get the title based on a playlist. I dont want it based on a playlist, I want it based on a stand-alone ID or URL.
Using a playlist query, the code uses:
if ([playlistID length] > 0) {
GTLServiceYouTube *service = self.youTubeService;
GTLQueryYouTube *query = [GTLQueryYouTube queryForPlaylistItemsListWithPart:#"snippet,contentDetails"];
query.playlistId = playlistID;
query.maxResults = 50;
_playlistItemListTicket = [service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLYouTubePlaylistItemListResponse *playlistItemList,
NSError *error) {
// Callback
_playlistItemList = playlistItemList;
_playlistFetchError = error;
_playlistItemListTicket = nil;
[self updateUI];
}];
}
Which I understand, but looking through GTLQueryYouTube I cant see anything that relates to a single video.
Does anybody have any ideas? Thanks!
Eventually I used:
GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
// Services which do not require sign-in may need an API key from the
service.APIKey = #"myKey";
GTLQueryYouTube *query = [GTLQueryYouTube queryForVideosListWithPart:#"id, snippet, fileDetails"];
query.identifier = #"xxxxxxxxxx, yyyyyyyyyy";
GTLServiceTicket *ticket = [service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
// This callback block is run when the fetch completes
if (error == nil) {
GTLYouTubeSearchListResponse *products = object;
// iteration of items and subscript access to items.
for (GTLYouTubeSearchResult *item in products) {
//NSMutableDictionary *dictionary = [item JSONValueForKey:#"id"];
GTLYouTubeThumbnailDetails *thumbnails = item.snippet.thumbnails;
GTLYouTubeThumbnail *thumbnail = thumbnails.high;
[imageArray addObject:thumbnail.url];
[titleArray addObject:item.snippet.title];
//NSLog(#"id: %#", [dictionary objectForKey:#"videoId"]);
//NSLog(#"Title: %#", item.snippet.title);
}
}else{
NSLog(#"Error: %#", error.description);
}
[self.thumbnailView reloadData];
}];
So created a queryForVideosListWithPart using a list of video ids separated by comma

iOS YouTube "No Filters Selected"

I'm trying to make a request for playListItems using the YouTube iOS SDK.
I'm getting back an error...
Error Domain=com.google.GTLJSONRPCErrorDomain
Code=-32602 "The operation couldn’t be completed. (No filter selected.)"
UserInfo=0x1568f1e0
{
error=No filter selected.,
GTLStructuredError=GTLErrorObject 0x1567fdf0: {message:"No filter selected." code:-32602 data:[1]},
NSLocalizedFailureReason=(No filter selected.)
}
The query I'm using is this...
GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
service.APIKey = #"my key";
// I suspect the problem is here...
GTLQueryYouTube *query = [GTLQueryYouTube queryForPlaylistItemsListWithPart:#"contentDetails"];
query.q = #"playlistId=<The playlist ID>";
GTLServiceTicket *ticket = [service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
if (!error) {
GTLYouTubePlaylistItemListResponse *playlistItems = object;
for (GTLYouTubePlaylistItem *playlistItem in playlistItems) {
GTLYouTubePlaylistItemContentDetails *details = playlistItem.contentDetails;
NSLog(#"PlaylistItem video ID = %#", details.videoId);
}
} else {
NSLog(#"%#", error);
}
}];
The problem is that the docs for the entire API are useless so there is no example of this being used. I'm having to put it together from the example for the Google Shopping apis and stuff.
Most of the guess work came from here.
Any ideas what I should put in the query.q value? Or if there's something else I'm missing?
OK, I finally found a link that shed some link on this.
The code to use is...
query.playlistId = #"the playlist ID";
Then everything worked :D

Resources