Jump to content
Sign in to follow this  

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")
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        case $Button1

Func _Rate()

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

    $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")
    if @error Then msgbox(64, "Info", "Connection Failed")
    $RECEIVED = $OBJ.ResponseText
    $sRECEIVED = StringReplace ( $RECEIVED, "Auth=", "")
    $asRECEIVED = StringReplace( $sRECEIVED, "YouTubeUser=hasermen", "")
        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: Gecko/20110420 Firefox/3.6.17')
    _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>')
    GUICtrlSetData($edit1, $hrequest)


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


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

Share this post

Link to post
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

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

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

Edited by athred

Share this post

Link to post
Share on other sites

Nvm, please close this Topic :unsure:

I solved my problem and it's working now :>

Share this post

Link to post
Share on other sites

Why don't you post your working code so someone else could need it if they ran into a problem like yours.

Share this post

Link to post
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
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.