senatin Posted August 15, 2021 Share Posted August 15, 2021 #include <MsgBoxConstants.au3> $video_id = '7HkUFRFnTJw'; Parliament - Night of The Thumpasorus Peoples $apikey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ; // browser key for desktop apps. ;$apikey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ; // server key for web apps. $ytquery = 'https://www.youtube.com/watch' & '?id=' & $video_id & '&key=' & $apikey ; $ytquery = $ytquery & '&part=snippet'; $ytquery = $ytquery & '&fields=displayMessage'; $ytdata = InetRead($ytquery,1); $ytjson = BinaryToString($ytdata); ;MsgBox($MB_OK, $video_id, $ytjson) ConsoleWrite( @CRLF & $ytjson & @CRLF) Exit I wanted to write into console the message from my livechat. When I provide the APIKey and Run the script, it give me <!DOCTYPE html><html style="font-size:......... and I hardly see the message chat because its too much output. Link to comment Share on other sites More sharing options...
Danp2 Posted August 15, 2021 Share Posted August 15, 2021 Looking at your code, it appears that you are simply reading the HTML page for a given video rather than making a valid API call. Can you point us to the API reference that shows the proper method of accessing the live chat? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
senatin Posted August 15, 2021 Author Share Posted August 15, 2021 (edited) Can I get A link that has a Valid API call. I couldnt find it. I have This API. And I get my API Key Here $ytquery = 'https://www.youtube.com/watch' & '?id=' & $video_id & '&key=' & $apikey ; $ytquery = $ytquery & '&part=snippet'; $ytquery = $ytquery & '&fields=displayMessage';] Isnt This command accessing the fields of named displayMessage? I wanted to get the content inside DisplayMessage. Edited August 15, 2021 by senatin Link to comment Share on other sites More sharing options...
Danp2 Posted August 15, 2021 Share Posted August 15, 2021 45 minutes ago, senatin said: Can I get A link that has a Valid API call. I couldnt find it. That's what I asked you to provide us. 🤔 48 minutes ago, senatin said: Isnt This command accessing the fields of named displayMessage? IDK, but it clearly isn't via a valid API call. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
senatin Posted August 15, 2021 Author Share Posted August 15, 2021 (edited) { "kind": "youtube#liveChatMessageListResponse", "etag": "B3IwHnXE3CBJTe4eCB7LNGYRA1Q", "pollingIntervalMillis": 1031, "pageInfo": { "totalResults": 1, "resultsPerPage": 1 }, "nextPageToken": "GKzm9OCms_ICIPXGq-Oms_IC", "items": [ { "kind": "youtube#liveChatMessage", "etag": "RnyZlS3ovUKQONFy0zNjOUodbKE", "id": "LCC.CikqJwoYVUNsbWVNcm1CUEQ2dC0wbDhnOG5CTGV3Egt2WU11aTd6OVRhdxI5ChpDUHZsOU9DbXNfSUNGZTRrclFZZE9MSUpiQRIbQ0xuMjVlaUlzX0lDRlZraEtnb2RsUW9MWlEx", "snippet": { "type": "textMessageEvent", "liveChatId": "KicKGFVDbG1lTXJtQlBENnQtMGw4ZzhuQkxldxILdllNdWk3ejlUYXc", "authorChannelId": "UClmeMrmBPD6t-0l8g8nBLew", "publishedAt": "2021-08-15T15:05:59.552812+00:00", "hasDisplayContent": true, "displayMessage": "test", "textMessageDetails": { "messageText": "test" } } } ] } This is from Live streaming API. I Think This is what Im trying to pull out. And Here is what I Did follow in some other tutorial on making Client ID for web application including the API Key. I Did Try to search for API call And I bump to other programming language and I could not find one with autoit. Is this the Right one using API CALL? let getYoutubeVideoData = async (youtubeVideoId) => { const response = await request .get('https://www.googleapis.com/youtube/v3/videos') .query({id: youtubeVideoId}) .query({key: process.env.YOUTUBE_API_KEY || "change-me-with-a-valid-youtube-key-if-you-need-me"}) //used only when saving youtube videos .query({part: 'snippet,contentDetails,statistics,status'}); let title = response.body.items[0].snippet.title; const tags = response.body.items[0].snippet.tags; const description = response.body.items[0].snippet.description; const publishedAt = response.body.items[0].snippet.publishedAt; const publishedOn = publishedAt.substring(0, publishedAt.indexOf('T')); const videoDuration = formatDuration(response.body.items[0].contentDetails.duration); if (title.endsWith('- YouTube')) { title = title.replace('- YouTube', ' - ' + videoDuration); } else { title = title + ' - ' + videoDuration; } let webpageData = { title: title, metaDescription: description.substring(0, 500), publishedOn: publishedOn, videoDuration: videoDuration } if(tags) { //some youtube videos might not have tags defined webpageData.tags = tags.slice(0,8).map(tag => tag.trim().replace(/\s+/g, '-')); } return webpageData; } And if so Then I must start searching for the request type in autoit. Edited August 15, 2021 by senatin Link to comment Share on other sites More sharing options...
Danp2 Posted August 15, 2021 Share Posted August 15, 2021 Maybe this will help you? senatin 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
senatin Posted August 15, 2021 Author Share Posted August 15, 2021 #include "YTAPI.au3" $linkadd = 'https://youtube.googleapis.com/youtube/v3/liveChat/messages?liveChatId=KicKGFVDbG1lTXJtQlBENnQtMGw4ZzhuQkxldxILdllNdWk3ejlUYXc&part=snippet&pageToken=GNyJvcjrs_ICIJWP_e7rs_IC' $apikey = 'xxxxxxxxxxxxxxxxxxxxxxxxx' $Video_ID = _YTApi_GetVideoID($linkadd & "&key=" & $apikey) If @error Then MsgBox(0, "VideoID", "The Video Failed:") EndIf $Video_Thumbnail = _YTApi_GetThumbnail($Video_ID) If Not @error Then MsgBox(0, "Thumbnail", "You can see the video thumbnail at this address:" & @CRLF & $Video_Thumbnail) EndIf $Video_Author = _YTApi_GetAuthor($Video_ID) If Not @error Then MsgBox(0, "Author", "The video author is: " & $Video_Author) EndIf I Got it Working With the right Link and API Key Thank you. After I check YTAPI.au3 script Func _YTApi_GetAuthor($s_ID) Local $sSource = __YTApi_GetSource($s_ID) If @error Then Return SetError(1, 0, "") Local $aRegex = StringRegExp($sSource, "<author><name>(.*?)</name>", 3) If @error Then Return SetError(1, 0, "") Return $aRegex[0] EndFunc ;==>_YTApi_GetAuthor I don't know how to change the StringRegExp($sSource, "<author><name>(.*?)</name>", 3) because The Output of the link provided by the API is Like this. { "kind": "youtube#liveChatMessageListResponse", "etag": "EnTTv_ybu6Pc5_CF1KDOuasvP6w", "pollingIntervalMillis": 5102, "pageInfo": { "totalResults": 1, "resultsPerPage": 1 }, "nextPageToken": "GMvi_pjvs_ICIM3P8Zzvs_IC", "items": [ { "kind": "youtube#liveChatMessage", "etag": "RCNOoo635-AvgA44NXkk0l_RlIY", "id": "LCC.CikqJwoYVUNsbWVNcm1CUEQ2dC0wbDhnOG5CTGV3Egt2WU11aTd6OVRhdxI5ChpDSnZpX3BqdnNfSUNGVUlHclFZZGwxZ0RiURIbQ0xuMjVlaUlzX0lDRlZraEtnb2RsUW9MWlEz", "snippet": { "type": "textMessageEvent", "liveChatId": "KicKGFVDbG1lTXJtQlBENnQtMGw4ZzhuQkxldxILdllNdWk3ejlUYXc", "authorChannelId": "UClmeMrmBPD6t-0l8g8nBLew", "publishedAt": "2021-08-15T20:30:04.509515+00:00", "hasDisplayContent": true, "displayMessage": "new item here", "textMessageDetails": { "messageText": "new item here" } } } ] } And I wanted to access nextPageToken and also the authorchannelID along with displayMessage. Link to comment Share on other sites More sharing options...
Solution Danp2 Posted August 15, 2021 Solution Share Posted August 15, 2021 The results are returning in JSON format. I would use this to parse the results -- senatin 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
senatin Posted August 16, 2021 Author Share Posted August 16, 2021 Thank you So much, Its so appreciated. I Go Look To it and Back Here after again. Hopefully I can Get to Next Step in my Target Goal. Link to comment Share on other sites More sharing options...
senatin Posted August 16, 2021 Author Share Posted August 16, 2021 (edited) expandcollapse popup#include "Json.au3" HotKeySet( "{ESC}", GoOut) #Region API $video_id = 'https://youtube.googleapis.com/youtube/v3/liveChat/messages?liveChatId=KicKGFVDbG1lTXJtQlBENnQtMGw4ZzhuQkxldxILRXFqdURWaFp4cnc&part=snippet' $apikey = 'xxxxxxxxxxx' #EndRegion $Json = $video_id & "&key=" & $apikey $Json = BinaryToString(InetRead($Json), 4) $Obj = Json_Decode($Json) While 1 $totalresults = Json_Get($Obj, '["pageInfo"]["totalResults"]') If @error Then ErrorSwitch(@error) If $totalresults = 0 Then Sleep(500) ContinueLoop EndIf For $i = 0 to $totalresults - 1 Step + 1 $displaymessage = Json_Get($Obj, '["items"][' & $i & ']["snippet"]["displayMessage"]') If @error Then ErrorSwitch(@error) ConsoleWrite($displaymessage & @LF) Next $nextpagetoken = Json_Get($Obj, '["nextPageToken"]') SetNewObj($nextpagetoken) WEnd Func SetNewObj($token) $Json = $video_id & "&pageToken=" & $token & "&key=" & $apikey ConsoleWrite($Json & @LF) $Json = BinaryToString(InetRead($Json), 4) ConsoleWrite($Json & @LF) $Obj = Json_Decode($Json) EndFunc Func ErrorSwitch($error) Switch $error Case 1 ConsoleWrite("Error 1: key not exists" & @LF) Case 2 ConsoleWrite("Error 2: syntax error" & @LF) EndSwitch Exit EndFunc Func GoOut() Exit EndFunc This Json.au3 works really well. But I Bumb to an error That make me confuse. $nextpagetoken = Json_Get($Obj, '["nextPageToken"]') ConsoleWrite(VarGetType($nextpagetoken) & " : " & $nextpagetoken & @LF) SetNewObj($nextpagetoken) WEnd $nextpagetoken has a String Value And adding it in the right place to the Link Address Func SetNewObj($token) $Json = $video_id & "&pageToken=" & $token & "&key=" & $apikey ConsoleWrite($Json & @LF) $Json = BinaryToString(InetRead($Json), 4) $Obj = Json_Decode($Json) EndFunc It shows The right Link as shown bellow the console. But Somehow It Doesn't Return Anything after Its been BinaryToString. I Tried To Copy the link and manually Open and Its working perfectly. If its the $Json = $vieo_id & "&pageToken=" & $token made it error then is there other way of combining 2 strings? Quote String : GJ3GgIeatvICIMH6jb2itvIChttps://youtube.googleapis.com/youtube/v3/liveChat/messages?liveChatId=KicKGFVDbG1lTXJtQlBENnQtMGw4ZzhuQkxldxILRXFqdURWaFp4cnc&part=snippet&pageToken=GJ3GgIeatvICIMH6jb2itvIC&key=AIz....................yM Error 1: key not exists +>03:24:44 AutoIt3.exe ended.rc:0 +>03:24:44 AutoIt3Wrapper Finished. >Exit code: 0 Time: 2.487 Edited August 16, 2021 by senatin Link to comment Share on other sites More sharing options...
Danp2 Posted August 16, 2021 Share Posted August 16, 2021 Can you post the complete contents of $Json following the API call? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
senatin Posted August 16, 2021 Author Share Posted August 16, 2021 (edited) { "kind": "youtube#liveChatMessageListResponse", "etag": "WB7JTJxr7gcgNItxGX_-jIhfG3E", "pollingIntervalMillis": 4770, "pageInfo": { "totalResults": 0, "resultsPerPage": 0 }, "nextPageToken": "GJ3GgIeatvICIPKr8_SctvIC", "items": [] } This is The Content With The New $Json. If I Try to do this Func SetNewObj($token) $Json = $video_id & "&pageToken=" & $token & "&key=" & $apikey $Json = BinaryToString(InetRead($Json), 4) ConsoleWrite($Json & @LF) $Obj = Json_Decode($Json) EndFunc CosoleWrite Return Nothing. Its Totally Empty. Edited August 17, 2021 by senatin Link to comment Share on other sites More sharing options...
Danp2 Posted August 16, 2021 Share Posted August 16, 2021 17 minutes ago, senatin said: CosoleWrite Return Nothing. Its Totally Empty. Add a ConsoleWrite for each individual variable. Then check the output to see if it meets your expectations. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
senatin Posted August 17, 2021 Author Share Posted August 17, 2021 (edited) I ReMade the Post Because I notice The Error Is found Here. Func SetNewObj($token) $Json = $video_id & "&pageToken=" & $token & "&key=" & $apikey ;"----- This Link is correct-----" ConsoleWrite($Json & @LF) $Json = BinaryToString(InetRead($Json), 4) ;"--------Here it return empty, unable to convert the Address Link------- " ConsoleWrite($Json & @LF) ;"-----Return Empty---------" $Obj = Json_Decode($Json) ;"------Give error Becuase Json is empty -----------" EndFunc This Script Return Console Like this +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. test on me ano yarn hindi pa kasi puno yung odins mo nyan nagrerecover pa dun sa video yung s video mo kasi, hindi pa puno yung odins kapag hindi pa puno yung odins, saka lang nadadagdagan yung odins every 12 at 8 100 na din weapon ko sa wakas accessories naman parang medyo mas madali sa accessories kasi level 25 lang bakit may mga scipt kana? test float kala ko script para sa ROX hahahah! test Baphomet String : GNDCqtKXuPICIJaHpfSZuPIC https://youtube.googleapis.com/youtube/v3/liveChat/messages?liveChatId=KicKGFVDbG1lTXJtQlBENnQtMGw4ZzhuQkxldxILdzFTbGVrSUZmOWc&part=snippet&pageToken=GNDCqtKXuPICIJaHpfSZuPIC&key=********** Error Error 1: key not exists +>21:51:42 AutoIt3.exe ended.rc:0 +>21:51:42 AutoIt3Wrapper Finished. >Exit code: 0 Time: 2.902 First before Getting the $nextpageToken The script along with the link is working fine. But after it include the TOken into the Link address The $Json = BinaryToString(InetRead($Json), 4)Return me Empty. as we can see to console it live a blank Tab. Thats Why When it call to Json_Decode The Scripts Give Error Saying that the $Index inside Json is Meant to be an Object. I Dont Understand Why The Link address When Provided to the BinaryToString become empty. I see That The variable with the link address is Arranged correctly. I Also Tried to access the $Json after using InetRead If InetRead($Json) = "" Then ConsoleWrite("Error Me"& @lf) Else ConsoleWrite("Im Zero" & @lf) EndIf And It Return me WIth Empty = "Error Me" Edited August 17, 2021 by senatin Link to comment Share on other sites More sharing options...
Danp2 Posted August 17, 2021 Share Posted August 17, 2021 56 minutes ago, senatin said: $Json = BinaryToString(InetRead($Json), 4) Suggest that you split this into two separate lines so that you can check the return value and @error following the call to InetRead and then BinaryToString. senatin 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
senatin Posted August 17, 2021 Author Share Posted August 17, 2021 (edited) Func SetNewObj($token) $Json = $video_id & "&pageToken=" & $token & "&key=" & $apikey ConsoleWrite($Json & @LF) $inetread = InetRead($Json) If @error Then ConsoleWrite(@error & @LF) ConsoleWrite($inetread & @LF) $Json = BinaryToString(InetRead($Json), 4) ConsoleWrite($Json & @LF) $Obj = Json_Decode($Json) EndFunc and the error for the inetread is 13 I looked from other forum and I Find it in inetget? Does the Link address with Token Need a credentials? Do I need To have like this scripts to access with credentials the Link? Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET","http://" & $sDomain & ":2086/xml-api/loadavg",False) $oHTTP.SetRequestHeader("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5") $oHTTP.SetCredentials($sUser,$sPass,0) $oHTTP.Send("") $sXML = $oHTTP.ResponseText() Answer: I finally Found A way how to Make it work here it is. Func SetNewObj($token) $Json = $video_id & "&pageToken=" & $token & "&key=" & $apikey ConsoleWrite($Json & @LF) Sleep(5000) ;"--------It Looks Like Its Loading ------------" $inetread = InetRead($Json) If @error Then ConsoleWrite(@error & @LF) ConsoleWrite($inetread & @LF) $Json = BinaryToString(InetRead($Json), 4) ConsoleWrite($Json & @LF) $Obj = Json_Decode($Json) EndFunc Now I'm going to Find A way to Know If the Page Is Ready To use. Edited August 17, 2021 by senatin Found Solution Link to comment Share on other sites More sharing options...
Danp2 Posted August 17, 2021 Share Posted August 17, 2021 2 hours ago, senatin said: Sleep(5000) ;"--------It Looks Like Its Loading ------------" I don't see why that would be required unless they have a limit on the number of transactions they will process per user. senatin 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
senatin Posted August 17, 2021 Author Share Posted August 17, 2021 (edited) I don't have any idea why that occur. First I added the Http Credentials, and I notice something odd if I Delayed accepting the messagebox Bug DOnt appear. So I ended Up Putting sleep and Voila Its now Working Fine. Func SetNewObj($token) $Json = $video_id & "&pageToken=" & $token & "&key=" & $apikey ConsoleWrite($Json & @LF) ;~ #Region Credential ;~ Local $REMOTE_URL = "http://localhost:***" ;~ Local $REMOTE_USER = "*****", $REMOTE_PASS = "r******TW0Pc" ;~ #EndRegion ;~ Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") ;~ $oHTTP.Open("GET", $Json, False) ;~ $oHTTP.SetRequestHeader("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5") ;~ $oHTTP.SetCredentials($REMOTE_USER,$REMOTE_PASS,0) ;~ $oHTTP.Send("") ;~ $sXML = $oHTTP.ResponseText() ;~ $oStatusCode = $oHTTP.Status GetObjLink($Json) EndFunc Func GetObjLink($link) While 1 Sleep(100) InetRead($link) If Not @error Then ExitLoop WEnd $Json = BinaryToString(InetRead($link), 4) ;ConsoleWrite($Json & @LF) $Obj = Json_Decode($Json) EndFunc Edited August 17, 2021 by senatin Forgot To *** username and pass Link to comment Share on other sites More sharing options...
Earthshine Posted August 18, 2021 Share Posted August 18, 2021 why can't you just loop while the JSON obj is empty? why use static sleeps at all? can you not detect in code when the object is empty? senatin 1 My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
senatin Posted August 29, 2021 Author Share Posted August 29, 2021 @Earthshineaw Im sorry for long time reply. I never got notified theres new reply on my Topic. After Reviewing my Topic I now see you. Anyway Yes I did Loop it using while. On 8/18/2021 at 1:05 AM, Danp2 said: I don't see why that would be required unless they have a limit on the number of transactions they will process per user. And Yes, It Does have Limit for a day for minute and so on. And Now Im Blending together Imagesearch to prevent exceeding limit. But Now Im Wondering if this will be the same case to Facebook Livestreaming API. But I'll leave it for now, Im still making my way to Completion on my own project. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now