Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
hugetv
Visitor

help please registered. Proceed code

Hello to all is that I found this code on the internet and it is just what I need to finish my channel aver if I can help with this as I do work me with php code

file: regScreen

function GetLinkingCode()
result = invalid

xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://roku.hankotv.com/xml/getLinkingCode")
response = xfer.GetToString()
xml = CreateObject("roXMLElement")
if xml.Parse(response)
result = {
code: xml.linkingCode.GetText()
expires: StrToI(xml.linkingCode@expires)
}
end if

return result
end function

function ValidateLinkingCode(linkingCode)
result = false

xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://roku.hankotv.com/xml/validateLinkingCode?code=" + linkingCode)
response = xfer.GetToString()
xml = CreateObject("roXMLElement")
if xml.Parse(response)
if UCase(xml.status.GetText()) = "SUCCESS"
sec = CreateObject("roRegistrySection", "mySection")
sec.Write("deviceToken", xml.deviceToken.GetText())
sec.Flush()

result = true
end if
end if

return result
end function

sub ShowLinkScreen()
dt = CreateObject("roDateTime")

' create a roCodeRegistrationScreen and assign it a roMessagePort
port = CreateObject("roMessagePort")
screen = CreateObject("roCodeRegistrationScreen")
screen.SetMessagePort(port)

' add some header text
screen.AddHeaderText("Link Your Account")
' add some buttons
screen.AddButton(1, "Get new code")
screen.AddButton(2, "Back")
' Add a short narrative explaining what this screen is
screen.AddParagraph("Before you can use this channel, you must link the channel to your account.")
' Focal text should give specific instructions to the user
screen.AddFocalText("Go to http://www.example.com/roku, log into your account, and enter the following code.", "spacing-normal")

' display a retrieving message until we get a linking code
screen.SetRegistrationCode("Retrieving...")
screen.Show()

' get a new code
linkingCode = GetLinkingCode()
if linkingCode <> invalid
screen.SetRegistrationCode(linkingCode.code)
else
screen.SetRegistrationCode("Failed to get code...")
end if

screen.Show()

while true
' we want to poll the API every 15 seconds for validation,
' so set a 15000 millisecond timeout on the Wait()
msg = Wait(15000, screen.GetMessagePort())

if msg = invalid
' poll the API for validation
if ValidateLinkingCode(linkingCode.code)
' if validation succeeded, close the screen
exit while
end if

dt.Mark()
if dt.AsSeconds() > linkingCode.expires
' the code expired. display a message, then get a new one
d = CreateObject("roMessageDialog")
dPort = CreateObject("roMessagePort")
d.SetMessagePort(dPort)
d.SetTitle("Code Expired")
d.SetText("This code has expired. Press OK to get a new one")
d.AddButton(1, "OK")
d.Show()

Wait(0, dPort)
d.Close()
screen.SetRegistrationCode("Retrieving...")
screen.Show()

linkingCode = GetLinkingCode()
if linkingCode <> invalid
screen.SetRegistrationCode(linkingCode.code)
else
screen.SetRegistrationCode("Failed to get code...")
end if
screen.Show()
end if
else if type(msg) = "roCodeRegistrationScreenEvent"
if msg.isScreenClosed()
exit while
else if msg.isButtonPressed()
if msg.GetIndex() = 1
' the user wants a new code
code = GetLinkingCode()
linkingCode = GetLinkingCode()
if linkingCode <> invalid
screen.SetRegistrationCode(linkingCode.code)
else
screen.SetRegistrationCode("Failed to get code...")
end if
screen.Show()
else if msg.GetIndex() = 2
' the user wants to close the screen
exit while
end if
end if
end if
end while

screen.Close()
end sub


I have this file to generate the ping
makepin.php

<?php

$random=rand(1679616, 60466175);
print base_convert($random,10,36);
?>


and I have this one to register when creating the code in mysql

checkcode.php

<?php

include "./conn.php";

// Get args
$code = !empty($_REQUEST['code']) ? mysql_real_escape_string($_REQUEST['code']) : "";

// Verify args

if (empty($code)) die("Missing or invalid Code");

$sql = "SELECT * FROM `users` WHERE code =\"" . $code."\"";
//echo "sql follows";
//echo "<br>";
//echo $sql;
// Get a specific result from the "example" table
$result = mysql_query($sql) or die(mysql_error());

// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array($result);
// Print out the contents of each row into a table

echo $row['code'];
?>


but I want to be able to do that when the code is confirmed that already exists can update another field the uniqueDeviceId

this

uniqueDeviceId=CreateObject("roDeviceInfo").GetDeviceUniqueId()
statusRequest=CreateObject("roUrlTransfer")
statusRequest.SetURL("http://example.com/index.php?d..."+uniqueDeviceId)
response=ParseJson(statusRequest.GetToString())
Our system http://www.rokumanager.com
0 Kudos
2 REPLIES 2
RokuJoel
Binge Watcher

Re: help please registered. Proceed code

Hi,

you make updates on your server via an HTTP POST, you would use a script on your server to store the value you POST to your database.

- Joel
0 Kudos
hugetv
Visitor

Re: help please registered. Proceed code

OK already solve it only I have the problem with that is breathing out the code very fast

<apiResponse>
<linkingCode expires="1310598793">ABC123</linkingCode>
</apiResponse>

How do I make that you last more time
Our system http://www.rokumanager.com
0 Kudos