0

Yahoo App Hosted Data

I am trying to create a new storage record and insert text into it.

I tried the code:

<div id='results'></div>
<?php
$yql_base_url = "http://query.yahooapis.com/v1/public/yql";
$yql_query = 'insert into yql.storage.admin (ZipCode) values ("43214")';
$yql_query_url = $yql_base_url . "?q=" . urlencode($yql_query);
$yql_query_url .= "&format=json";
$session = curl_init($yql_query_url);
curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
$json = curl_exec($session);
echo 'Save zip code json results:' . $json . '!';
?>


I got the response:
Save zip code json results:{"error":{"lang":"en-US","description":"Unable to execute YQL statement, wrong HTTP verb. Allowed HTTP methods for INSERT are PUT, POST and DELETE or GET with JSONP"}}!

Yahoo API says to use code: insert into yql.storage.admin

then I tried Using the code

<?php
$BASE_URL = "https://query.yahooapis.com/v1/public/yql";
$Submitted = 'insert into yql.storage.admin ("ZipCode") values ("43214")&format=json';
echo "checking for Take II results"
if(*yql.storage.admin.results) {
echo 'Take II yql.storage.admin' . $yql.storage.admin.results . '!';
}
?>


We get error:

PHP Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in /usr/home/myspamg/www/htdocs/yap/Bob/CanvasView.php on line 275

How do I fix this error?

4 Replies
  • Try to remove the '*' in the line

    if(*yql.storage.admin.results) {


    QUOTE (My Spam Gone Team @ Nov 18 2010, 01:16 PM) <{POST_SNAPBACK}>
    I am trying to create a new storage record and insert text into it.

    I tried the code:

    <div id='results'></div>
    <?php
    $yql_base_url = "http://query.yahooapis.com/v1/public/yql";
    $yql_query = 'insert into yql.storage.admin (ZipCode) values ("43214")';
    $yql_query_url = $yql_base_url . "?q=" . urlencode($yql_query);
    $yql_query_url .= "&format=json";
    $session = curl_init($yql_query_url);
    curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
    $json = curl_exec($session);
    echo 'Save zip code json results:' . $json . '!';
    ?>


    I got the response:
    Save zip code json results:{"error":{"lang":"en-US","description":"Unable to execute YQL statement, wrong HTTP verb. Allowed HTTP methods for INSERT are PUT, POST and DELETE or GET with JSONP"}}!

    Yahoo API says to use code: insert into yql.storage.admin

    then I tried Using the code

    <?php
    $BASE_URL = "https://query.yahooapis.com/v1/public/yql";
    $Submitted = 'insert into yql.storage.admin ("ZipCode") values ("43214")&format=json';
    echo "checking for Take II results"
    if(*yql.storage.admin.results) {
    echo 'Take II yql.storage.admin' . $yql.storage.admin.results . '!';
    }
    ?>


    We get error:

    PHP Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in /usr/home/myspamg/www/htdocs/yap/Bob/CanvasView.php on line 275

    How do I fix this error?
    0
  • Hi,

    It looks like you're missing a semicolon after your echo statement: echo "checking for Take II results" --> echo "checking for Take II results";

    It also looks like you're using GET to make your request. Try using PUT or POST. You can try it out on the command line like this:
    $ curl -X POST -H "Content-Length:0" "http://query.yahooapis.com/v1/public/yql?q=insert%20into%20yql.storage.admin%20(value)%20values%20(%22foo%22)&diagnostics=true"

    Also, the yql.storage.admin table only has "url", "value", and "name" keys. It doesn't have a "ZipCode" key. You can run desc on tables in the yql console to see which keys they support: http://y.ahoo.it/LRK9dPKe




    QUOTE (My Spam Gone Team @ Nov 18 2010, 01:16 PM) <{POST_SNAPBACK}>
    I am trying to create a new storage record and insert text into it.

    I tried the code:

    <div id='results'></div>
    <?php
    $yql_base_url = "http://query.yahooapis.com/v1/public/yql";
    $yql_query = 'insert into yql.storage.admin (ZipCode) values ("43214")';
    $yql_query_url = $yql_base_url . "?q=" . urlencode($yql_query);
    $yql_query_url .= "&format=json";
    $session = curl_init($yql_query_url);
    curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
    $json = curl_exec($session);
    echo 'Save zip code json results:' . $json . '!';
    ?>


    I got the response:
    Save zip code json results:{"error":{"lang":"en-US","description":"Unable to execute YQL statement, wrong HTTP verb. Allowed HTTP methods for INSERT are PUT, POST and DELETE or GET with JSONP"}}!

    Yahoo API says to use code: insert into yql.storage.admin

    then I tried Using the code

    <?php
    $BASE_URL = "https://query.yahooapis.com/v1/public/yql";
    $Submitted = 'insert into yql.storage.admin ("ZipCode") values ("43214")&format=json';
    echo "checking for Take II results"
    if(*yql.storage.admin.results) {
    echo 'Take II yql.storage.admin' . $yql.storage.admin.results . '!';
    }
    ?>


    We get error:

    PHP Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in /usr/home/myspamg/www/htdocs/yap/Bob/CanvasView.php on line 275

    How do I fix this error?
    0
  • Yep, agree with Erik,

    A part from the semicolon type, you will need to perform a PUT or POST request.

    Anyway, I will also recommend, instead of using directly curl, using the Yahoo! YOS sdk:

    http://developer.yahoo.com/social/sdk/php/

    It will simplify your life a lot!

    CODE
        <?php  
    $query = sprintf("select * from geo.places where text='ballard';");
    $response = $session->query($query);

    print_r($response);
    ?>


    Cheers!
    Francisco.

    QUOTE (Erik @ Nov 18 2010, 02:55 PM) <{POST_SNAPBACK}>
    Hi,

    It looks like you're missing a semicolon after your echo statement: echo "checking for Take II results" --> echo "checking for Take II results";

    It also looks like you're using GET to make your request. Try using PUT or POST. You can try it out on the command line like this:
    $ curl -X POST -H "Content-Length:0" "http://query.yahooapis.com/v1/public/yql?q=insert%20into%20yql.storage.admin%20(value)%20values%20(%22foo%22)&diagnostics=true"

    Also, the yql.storage.admin table only has "url", "value", and "name" keys. It doesn't have a "ZipCode" key. You can run desc on tables in the yql console to see which keys they support: http://y.ahoo.it/LRK9dPKe
    0
  • Thanks guys for all the help, it's very appreciated :)
    0

Recent Posts

in YQL