Showing posts with label commands. Show all posts
Showing posts with label commands. Show all posts

Sunday, July 20, 2014

Videos from youtube channel in iOS app (part 2)

We want to display list of channel's uploads. That list has an identifier, we need to find out, and it can be done with this request:
1. Channel details.

- (void) channelDetails {
   GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
   service.APIKey = API_KEY;
   GTLQueryYouTube *query = [GTLQueryYouTube queryForChannelsListWithPart:@"contentDetails"];
   query.forUsername = CHANNEL_NAME;
   [service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
      if (!error) {
          GTLYouTubeChannelListResponse *items = object;
          for (GTLYouTubeChannelListResponse * item in items){
             NSLog(@"item: %@", item.JSON[@"contentDetails"]); 
          }
      } else{
           NSLog(@"%@", error);
      }
   }];
}


Response is in this format:

item: {
   googlePlusUserId = XXXXXXXXXX;
   relatedPlaylists = {
       uploads = "YYYYYYYYYYYYY";
   };
}

Store the value from "uploads" field to UPLOADS_LIST_ID.

2. List of uploaded videos. To receive list of uploaded videos we need to make a playlist items query with UPLOADS_LIST_ID as playlist id.


- (void) getUploads {
   GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];   service.APIKey = API_KEY;
   GTLQueryYouTube *query = [GTLQueryYouTube queryForPlaylistItemsListWithPart:@"id,snippet"];
   query.playlistId = UPLOADS_LIST_ID;
   query.maxResults = MAX_RESULTS; 
   [service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
      if (!error) {
         GTLYouTubePlaylistItemListResponse *playlistItems = object;
         for (GTLYouTubePlaylistItem *playlistItem in playlistItems) {
            [self.identifiers addObject:playlistItem.snippet.resourceId.JSON[@"videoId"]];
         }
      [self getVideos];
     }else {
      NSLog(@"%@", error);
     }
   }];
}

3. List of uploaded videos with all information. Playlist queries, like one from above give us list of videos with details like: video id, title and thumbnail. To be able to read information like video duration and number of views, we need to make video list query. We can use list of video identifiers as filter for that query. For that reason we stored them in self.identifiers property of NSMutableDictionary type.

- (void) getVideos {
   GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
   service.APIKey = API_KEY;
   GTLQueryYouTube *query = [GTLQueryYouTube queryForVideosListWithPart:@"id, snippet, contentDetails, statistics, player"];
   query.identifier = [[self.identifiers valueForKey:@"description"] componentsJoinedByString:@","];
   [service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error){
      if (!error) {
         GTLYouTubeVideoListResponse *videolistItems = object;
         for (GTLYouTubeVideo *videoItem in videolistItems){
            [self.dataSource addObject:videoItem];
         }
         [self.tableView reloadData]; 
      } else {
      NSLog(@"%@", error);
      }
   }];
}

You may also need query for list of playlists for fetching all information from one channel. For this query we will need CHANNEL_ID, not name.
4. List of channel's playlists:

- (void) loadPlaylists {
   GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
   service.APIKey = API_KEY;
   GTLQueryYouTube *query = [GTLQueryYouTube queryForPlaylistsListWithPart:@"id, snippet, contentDetails"];
   query.channelId = CHANNEL_ID;
   query.maxResults = MAX_RESULTS;
   [service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
      if (!error) {
         GTLYouTubePlaylistListResponse *items = object;
         for (GTLYouTubePlaylist * item in items) {
            [self.dataSource addObject:item];
         }
         [self.tableView reloadData];
      } else {
         NSLog(@"%@", error);
      }
   }];
}

Friday, July 19, 2013

Git Tips



This article is intended as a basic manual for iOS developers that are using git source control, but need more than built in options in xCode.

For that we will need to open Terminal application located in Applications/Utilities. Use 'ls' command to see content of the current folder, and 'cd FOLDER_NAME' to open specific subfolder. Command 'cd ..' will open parent folder.

If you want to simply clone repository from remote repository then run this command in your terminal:
git clone HTTPS_ORIGINAL_REMOTE_REPOSITORY.git
This will clone project to the current folder.

Second scenario is that you want to add existing project to remote repository. Go to the folder that contains your .xcodeproj project file.

To check current status:
git status
When your code is already tracked by Git, and you want to change the repository, you have two options.

1. Remove git tracking and start fresh:
rm -rf .git
2. Set new repository as your origin to push to.
git remote set-url origin HTTPS_NEW_REMOTE_REPOSITORY.git
To start git tracking, initialize empty git
git init
Next step is to add original remote repository, which you acquire at your git hosting service, e.g. Bitbucket
git remote add origin HTTPS_ORIGINAL_REMOTE_REPOSITORY.git
Add all files from your project directory
git add --all
Commit
git commit -m "Initial Commit"
Push
git push origin master
Your project is now pushed to remote repository.