ricardoalcocer / appc_book_code

This repository contains all the source code for the book Build Native Cross-Platform Apps with Appcelerator. For more information about the book, visit http://buildmobileapps.io.
10 stars 13 forks source link

Ch 6 Youtube API V 2.0 Deprecated #5

Closed safadig closed 8 years ago

safadig commented 9 years ago

YouTube no longer works and shows only support video since API v2.0 has been deprecated

ricardoalcocer commented 9 years ago

Thanks. Realized this yesterday as I was refactoring the code. Will look into it within the next couple days.

ricardoalcocer commented 9 years ago

For the sake of documenting, I'll write here my findings.

  1. You need to create a "key for browser applications" over at https://console.developers.google.com . This is done by logging in with your GMail address
  2. Grab that key and hold on to it, just like you did with the Twitter key.
  3. Next, you need to do two different steps in order to be able to get a list of videos. The details can be found in this video: https://www.youtube.com/watch?v=RjUlmco7v2M . The gist is that you first make a call for youtube.channels.list, grab the "uploads" id, and then make a call to youtube.playlistItems.list. That will return a JSON string like:

{
 "kind": "youtube#playlistItemListResponse",
 "etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/P_AJyHq1yQjaIjxC0mh9fgr8LqI\"",
 "pageInfo": {
  "totalResults": 11,
  "resultsPerPage": 50
 },
 "items": [
  {
   "kind": "youtube#playlistItem",
   "etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/zYEpHI3EGh2TXZ9Znot3doOGsmk\"",
   "id": "UU3dc9180X44z9DwxY_ztyLLgNJ7KwaISU",
   "snippet": {
    "publishedAt": "2014-08-10T01:01:19.000Z",
    "channelId": "UC6zpQ6JVCaV7DVJghDlYSog",
    "title": "Tony MacAlpine - The Violin Song",
    "description": "This is the solo and outro of The Violin Song by Tony MacAlpine played on August 8, 2014 at Biscuits and Blues, San Francisco CA",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/yjvLJqOcBCI/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/yjvLJqOcBCI/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/yjvLJqOcBCI/hqdefault.jpg",
      "width": 480,
      "height": 360
     },
     "standard": {
      "url": "https://i.ytimg.com/vi/yjvLJqOcBCI/sddefault.jpg",
      "width": 640,
      "height": 480
     },
     "maxres": {
      "url": "https://i.ytimg.com/vi/yjvLJqOcBCI/maxresdefault.jpg",
      "width": 1280,
      "height": 720
     }
    },
    "channelTitle": "Ricardo Alcocer",
    "playlistId": "UU6zpQ6JVCaV7DVJghDlYSog",
    "position": 0,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "yjvLJqOcBCI"
    }
   }
  },
  {
   "kind": "youtube#playlistItem",
   "etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/H2G8siVfCrJtJF1TMD5CiY7LHZc\"",
   "id": "UU3dc9180X44wmzWT6r8u7rFL2kOhTAmNY",
   "snippet": {
    "publishedAt": "2014-07-28T18:05:47.000Z",
    "channelId": "UC6zpQ6JVCaV7DVJghDlYSog",
    "title": "Quick card puzzle",
    "description": "Relearning TailSpin by John Guastaferro",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/Q92CHlBp4s4/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/Q92CHlBp4s4/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/Q92CHlBp4s4/hqdefault.jpg",
      "width": 480,
      "height": 360
     },
     "standard": {
      "url": "https://i.ytimg.com/vi/Q92CHlBp4s4/sddefault.jpg",
      "width": 640,
      "height": 480
     },
     "maxres": {
      "url": "https://i.ytimg.com/vi/Q92CHlBp4s4/maxresdefault.jpg",
      "width": 1280,
      "height": 720
     }
    },
    "channelTitle": "Ricardo Alcocer",
    "playlistId": "UU6zpQ6JVCaV7DVJghDlYSog",
    "position": 1,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "Q92CHlBp4s4"
    }
   }
  },
  {
   "kind": "youtube#playlistItem",
   "etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/LC8FeLjTMlbLP3AejUZmdyLY6WM\"",
   "id": "UU3dc9180X44xZ37Uifp2T4E8PskvqN8Qu",
   "snippet": {
    "publishedAt": "2014-04-11T22:30:17.000Z",
    "channelId": "UC6zpQ6JVCaV7DVJghDlYSog",
    "title": "DrawerMenu Alloy Widget Example",
    "description": "An example of how my Drawer Menu Alloy Widget works.  Find the widget at https://github.com/ricardoalcocer/alloy-widget-drawermenu",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/-m8KGaYEWoI/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/-m8KGaYEWoI/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/-m8KGaYEWoI/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "Ricardo Alcocer",
    "playlistId": "UU6zpQ6JVCaV7DVJghDlYSog",
    "position": 2,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "-m8KGaYEWoI"
    }
   }
  },
  {
   "kind": "youtube#playlistItem",
   "etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/3mQg4uWCnWpoA_F3kqcYSv9kmGs\"",
   "id": "UU3dc9180X44xKCT-Mog8T_qhSfZjE5NAF",
   "snippet": {
    "publishedAt": "2013-03-02T13:57:44.000Z",
    "channelId": "UC6zpQ6JVCaV7DVJghDlYSog",
    "title": "HackPR",
    "description": "",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/VR5Ffge5714/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/VR5Ffge5714/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/VR5Ffge5714/hqdefault.jpg",
      "width": 480,
      "height": 360
     },
     "standard": {
      "url": "https://i.ytimg.com/vi/VR5Ffge5714/sddefault.jpg",
      "width": 640,
      "height": 480
     }
    },
    "channelTitle": "Ricardo Alcocer",
    "playlistId": "UU6zpQ6JVCaV7DVJghDlYSog",
    "position": 3,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "VR5Ffge5714"
    }
   }
  },
  {
   "kind": "youtube#playlistItem",
   "etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/kqK4F0diKMr7YgfW6HDtZ4GUhkM\"",
   "id": "UU3dc9180X44wiAAoNBFooSJEpFVsIfQts",
   "snippet": {
    "publishedAt": "2008-09-29T16:08:10.000Z",
    "channelId": "UC6zpQ6JVCaV7DVJghDlYSog",
    "title": "Alco meets bond",
    "description": "My humble tribute to Bond.  Me playing the guitar.  Never got to finish it, but it's really cool I think.",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/ChISi6FNQSI/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/ChISi6FNQSI/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/ChISi6FNQSI/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "Ricardo Alcocer",
    "playlistId": "UU6zpQ6JVCaV7DVJghDlYSog",
    "position": 4,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "ChISi6FNQSI"
    }
   }
  },
  {
   "kind": "youtube#playlistItem",
   "etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/FmsEi7NDQcAtIuukdCNdthAPsi0\"",
   "id": "UU3dc9180X44xXL3GSDeVO742WnEvkTdL-",
   "snippet": {
    "publishedAt": "2008-08-21T21:33:23.000Z",
    "channelId": "UC6zpQ6JVCaV7DVJghDlYSog",
    "title": "That's what friends are for",
    "description": "Your friends should be there right when you need them",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/4aqUGuP-5zs/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/4aqUGuP-5zs/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/4aqUGuP-5zs/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "Ricardo Alcocer",
    "playlistId": "UU6zpQ6JVCaV7DVJghDlYSog",
    "position": 5,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "4aqUGuP-5zs"
    }
   }
  },
  {
   "kind": "youtube#playlistItem",
   "etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/ZLz6ruLQ1bzAt3eUmdAm2AOVZaw\"",
   "id": "UU3dc9180X44zuICRtAN2sbn5NLCgCOezq",
   "snippet": {
    "publishedAt": "2007-02-22T17:47:03.000Z",
    "channelId": "UC6zpQ6JVCaV7DVJghDlYSog",
    "title": "Glade Plug-ups",
    "description": "Pop one up you rear end and you're set.",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/HLJoY0-2nKA/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/HLJoY0-2nKA/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/HLJoY0-2nKA/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "Ricardo Alcocer",
    "playlistId": "UU6zpQ6JVCaV7DVJghDlYSog",
    "position": 6,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "HLJoY0-2nKA"
    }
   }
  },
  {
   "kind": "youtube#playlistItem",
   "etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/QvU-IybozZOq6d7gh_gQbKP2PKE\"",
   "id": "UU3dc9180X44w2i4poIf6QxZ8s2TkUlugW",
   "snippet": {
    "publishedAt": "2006-11-24T18:50:47.000Z",
    "channelId": "UC6zpQ6JVCaV7DVJghDlYSog",
    "title": "Kissing prank",
    "description": "A kiss is a kiss...is it not?",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/IMMCGF3zjQ4/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/IMMCGF3zjQ4/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/IMMCGF3zjQ4/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "Ricardo Alcocer",
    "playlistId": "UU6zpQ6JVCaV7DVJghDlYSog",
    "position": 7,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "IMMCGF3zjQ4"
    }
   }
  },
  {
   "kind": "youtube#playlistItem",
   "etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/xHGuV-Vq9WWNADvI54jcfF0TPpc\"",
   "id": "UU3dc9180X44x7NX36sEzdtlXYyPB8kyG7",
   "snippet": {
    "publishedAt": "2006-11-09T14:38:22.000Z",
    "channelId": "UC6zpQ6JVCaV7DVJghDlYSog",
    "title": "So you think you're a great lover",
    "description": "So you think you're a great lover",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/RHYxV5vx_oo/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/RHYxV5vx_oo/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/RHYxV5vx_oo/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "Ricardo Alcocer",
    "playlistId": "UU6zpQ6JVCaV7DVJghDlYSog",
    "position": 8,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "RHYxV5vx_oo"
    }
   }
  },
  {
   "kind": "youtube#playlistItem",
   "etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/dVSCOIJh1qtMnmDyBtJ9qWlCbZQ\"",
   "id": "UU3dc9180X44zdx0TznqrOLQDisCtNRREj",
   "snippet": {
    "publishedAt": "2006-08-21T15:18:32.000Z",
    "channelId": "UC6zpQ6JVCaV7DVJghDlYSog",
    "title": "Don't drink and skate",
    "description": "If you drink, don't skate....and don't cover your face with a scarf.",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/OD5mrFsVRO4/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/OD5mrFsVRO4/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/OD5mrFsVRO4/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "Ricardo Alcocer",
    "playlistId": "UU6zpQ6JVCaV7DVJghDlYSog",
    "position": 9,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "OD5mrFsVRO4"
    }
   }
  },
  {
   "kind": "youtube#playlistItem",
   "etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/3I0D5QUw31SVpiSzvre3wDETLN8\"",
   "id": "UU3dc9180X44zB_RQ72p-upWiW4iyKd567",
   "snippet": {
    "publishedAt": "2006-08-21T15:10:28.000Z",
    "channelId": "UC6zpQ6JVCaV7DVJghDlYSog",
    "title": "Mei-lin Yamilette",
    "description": "El viernes 18 cumplo 28",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/ExYHfh_aJTk/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/ExYHfh_aJTk/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/ExYHfh_aJTk/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "Ricardo Alcocer",
    "playlistId": "UU6zpQ6JVCaV7DVJghDlYSog",
    "position": 10,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "ExYHfh_aJTk"
    }
   }
  }
 ]
}

At the end of each object, there's a resourceId property that holds the video id to be used to construct the URL.

resourceId: {
kind: "youtube#video",
videoId: "Q92CHlBp4s4"
}

For this example above, the video URL will be:

https://www.youtube.com/watch?v=Q92CHlBp4s4


The first call you can make only once and save that "uploads" id in your app. Then your 2nd call will look something like this:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=UU6zpQ6JVCaV7DVJghDlYSog&key={YOUR_API_KEY}

...replacing {YOUR_API_KEY} with your actual key.

I'll work on refactoring this part of the code later this weekend or next week.

safadig commented 9 years ago

Thanks... V3 really open ups the option for having nested lists that combine multiple playlists  Really Cool!

Ghassan

  From: Ricardo Alcocer <notifications@github.com>

To: ricardoalcocer/appc_book_code appc_book_code@noreply.github.com Cc: safadig safadig@yahoo.com Sent: Friday, May 29, 2015 6:03 PM Subject: Re: [appc_book_code] Ch 6 Youtube API V 2.0 Deprecated (#5)

For the sake of documenting, I'll write here my findings.

safadig commented 9 years ago

Ricardo,I can get the code to work great with single playlist. I have spent numerous hours ( and still working on it!) trying to get a child controller form a Playlist listview to open separate/different  corresponding playlists from my channel. I hope you would give it some consideration when you update the code to have it so that more than one Playlist can be selected (master/child). Thanks again Ghassan

  From: Ricardo Alcocer <notifications@github.com>

To: ricardoalcocer/appc_book_code appc_book_code@noreply.github.com Cc: safadig safadig@yahoo.com Sent: Friday, May 29, 2015 6:03 PM Subject: Re: [appc_book_code] Ch 6 Youtube API V 2.0 Deprecated (#5)

For the sake of documenting, I'll write here my findings.