Jump to content

Youtube API problem


Recommended Posts

Hi, i have problems with adding rating. I tried to post "like" but i have error called "Premature end of file."

I dont have any idea why :/

Here's code

Global $DESCRIPTOR = "Signa5 Test"
$user = "czokobongo"
$pass = "czokobonkgo"

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <winhttp.au3>

Global $hOpen = _WinHttpOpen()
Global $sChunk, $sData

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 449, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 56, 24, 213, 49, $WS_GROUP)
$button2 = GUICtrlCreateButton("Like", 350, 24, 213, 49, $WS_GROUP)
$Edit1 = GUICtrlCreateEdit("", 16, 88, 593, 337)
GUICtrlSetData(-1, "Edit1")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Button1
            _Rate()
    EndSwitch
WEnd


Func _Rate()

    $ip = TCPNameToIP ("https://www.google.com/youtube/accounts/ClientLogin")
    ConsoleWrite($ip)

    $Developer_Key = "AI39si471eJAOdgyvJ40D4xlgoZ8UfK3FEk0i_UcFUksmJQZxPGOCSw4tqXeJGYrZsJkSg9WJ2XLPdqcOMe_fkqpLkOJ1cQXEg"
    $Url = "https://www.google.com/youtube/accounts/ClientLogin"
    $POSTDATA = "Email="PASTE_HERE_YOUR_YT_USERNAME&"&Passwd="PASTE_HERE_YOUR_YT_PASSWORD&"&service=youtube&source="&"RatingTz"
    $OBJ = ObjCreate("WinHttp.WinHttpRequest.5.1")
    $OBJ.Open("POST", $URL, False)
    $OBJ.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
    $OBJ.Send($POSTDATA)
    if @error Then msgbox(64, "Info", "Connection Failed")
    $RECEIVED = $OBJ.ResponseText
    $sRECEIVED = StringReplace ( $RECEIVED, "Auth=", "")
    $asRECEIVED = StringReplace( $sRECEIVED, "YouTubeUser=hasermen", "")
    $AUTHKEY = $asRECEIVED
    ConsoleWrite($AUTHKEY)
        GuiCtrlSetData($edit1, $RECEIVED &@CRLF&@CRLF, "append")

    $YT_SITE = "gdata.youtube.com"
    $YT_PATH = "/feeds/api/videos/Cdnjx56JCJ8/ratings"

    $HSESSION = _WINHTTPOPEN('Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17')
    $HCONNECT = _WINHTTPCONNECT($HSESSION, $YT_SITE)
    $HREQUEST = _WINHTTPOPENREQUEST($HCONNECT, "POST", $YT_PATH)
    _WinHttpAddRequestHeaders($hrequest, 'Accept: text/*')
    ;_WinHttpAddRequestHeaders($hRequest, 'Content-Length: ')
    _WinHttpAddRequestHeaders($hRequest, 'Authorization: GoogleLogin auth='&$AUTHKEY)
    _WinHttpAddRequestHeaders($hRequest, 'Gata-Version: 2')
    _WinHttpAddRequestHeaders($hRequest, 'X-GData-Key: key='&$DEVELOPER_KEY & @CRLF)
    _WinHttpAddRequestHeaders($hRequest, 'Content-Type: application/atom+xml')
    _WinHttpAddRequestHeaders($hRequest, '<?xml version="1.0" encoding="UTF-8"?>')
    _WinHttpAddRequestHeaders($hRequest, '<entry xmlns="http://www.w3.org/2005/Atom"')
    _WinHttpAddRequestHeaders($hRequest, 'xmlns:yt="http://gdata.youtube.com/schemas/2007">')
    _WinHttpAddRequestHeaders($hRequest, '<yt:rating value="like"/>')
    _WinHttpAddRequestHeaders($hRequest, '</entry>')
    _WinHttpSendRequest($hRequest)
    GUICtrlSetData($edit1, $hrequest)

    _WinHttpReceiveResponse($hRequest)

        If _WinHttpQueryDataAvailable($hRequest) Then
                While 1
                $sChunk = _WinHttpReadData($hRequest)
                    If @error Then ExitLoop
                    $sData &= $sChunk
                WEnd
    GUICtrlSetData($edit1, $sdata, "append")
            Else
    MsgBox(48, "Error", "Site is experiencing problems.")
    EndIf

;_WinHttpCloseHandle($hRequest)
;_WinHttpCloseHandle($hConnect)
;_WinHttpCloseHandle($hOpen)
EndFunc

I know its "simple', but i only need 1 button and edit on form :unsure:

Please help me with this "Premature end of file." error

Edited by athred
Link to comment
Share on other sites

I can't edit it now :/

Request should looks like this

POST /feeds/api/videos/VIDEO_ID/ratings
Host: gdata.youtube.com
Content-Type: application/atom+xml
Content-Length: CONTENT_LENGTH
Authorization: AuthSub token="AUTHORIZATION_TOKEN"
GData-Version: 2
X-GData-Key: key=DEVELOPER_KEY

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom"
       xmlns:yt="http://gdata.youtube.com/schemas/2007">
  <yt:rating value="like"/>
</entry>

*from http://code.google.com/intl/pl-PL/apis/youtube/2.0/developers_guide_protocol_ratings.html

Edited by athred
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...