Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Public NextPageToken As String
Public PageToken As String
Public Completed = False
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim parser As JSONParser
Dim playlistID As String = "PLsyeobzWxl7oZ-fxDYkOToURHhMuWD1BK"
Dim YTAPIkey As String = "AIzaSyCCU4tGcGaNf3GVjWoyoTgd6rHgn8TsMtE"
'Private Button1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("P1")
If FirstTime Then
GetYTVideos
Else
GetYTVideos
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Private Sub GetYTVideos()
'Do While PageToken = NextPageToken
Log("PageToken: " & PageToken)
YTPlayListRequest
'Loop
End Sub
Private Sub YTPlayListRequest()
'PageToken = NextPageToken
Dim URLtoGET As String = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&pageToken=" & NextPageToken & "&playlistId="& playlistID &"&key=" & YTAPIkey
Log(URLtoGET)
Dim J As HttpJob
J.Initialize("ytGetJob", Me)
J.Download (URLtoGET)
J.GetRequest.SetHeader("Accept","text/html, application/xhtml+xml, image/jxr, */*")
J.GetRequest.SetHeader("Host", "www.googleapis.com")
J.GetRequest.SetHeader("Connection", "Keep-Alive")
ProgressDialogShow("Searching for Tutorial Videos...")
Log("Searching for videos")
End Sub
Sub JobDone (Job As HttpJob)
Dim ytGETresult As String
Log("Job Done Started ")
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Select Job.JobName
Case "ytGetJob"
'print the result to the logs
ytGETresult = Job.GetString
ProgressDialogHide
'Log(Job.GetString)
'ParseResult(Job.GetString)
ParseResponse(Job.GetString)
End Select
Else
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
'Call the next page if there was not error and the page token has changed
If Job.Success And Not(Completed) Then YTPlayListRequest
End Sub
Private Sub ParseResponse(text As String)
parser.Initialize(text)
Log("parser started ")
Dim root As Map = parser.NextObject
Dim NextPageToken As String = root.Get("nextPageToken")
Dim items As List = root.Get("items")
For Each colitems As Map In items
Dim snippet As Map = colitems.Get("snippet")
Dim playlistID As String = snippet.Get("playlistId")
Dim resourceId As Map = snippet.Get("resourceId")
Dim videoId As String = resourceId.Get("videoId")
Dim title As String = snippet.Get("title")
Dim thumbnails As Map = snippet.Get("thumbnails")
' Dim standard As Map = thumbnails.Get("standard")
' Dim width As Int = standard.Get("width")
' Dim url As String = standard.Get("url")
' Dim height As Int = standard.Get("height")
Dim default As Map = thumbnails.Get("default")
Dim width As Int = default.Get("width")
Dim url As String = default.Get("url")
Dim height As Int = default.Get("height")
' Dim high As Map = thumbnails.Get("high")
' Dim width As Int = high.Get("width")
' Dim url As String = high.Get("url")
' Dim height As Int = high.Get("height")
' Dim medium As Map = thumbnails.Get("medium")
' Dim width As Int = medium.Get("width")
' Dim url As String = medium.Get("url")
' Dim height As Int = medium.Get("height")
Next
Log("NextPageToken " & NextPageToken)
'Check that the page token has changed, if not then set the completed flag
If PageToken = NextPageToken Then Completed = True
PageToken = NextPageToken
End Sub