0

PUT method in SET STATUS API

Hi
I was able to use all Social APIs including GET STATUS API. But for setting the status, when i use PUT Method, it says please provide valid credentials.
Kindly explain what could be the problem. I'm passing all the Oauth Parameters required but still don't know why it's not working.
Kindly suggest

THANKS
ANKIT

12 Replies
  • Hi Ankit,

    Based on the error you're getting, try putting your OAuth params in the request header.

    I was able to successfull update my status using this PHP:

    require('yosdk/lib/OAuth.php');//OAuth lib ships w/ Y! PHP SDK
    //key secret for client/desktop app
    $key = '{key}';
    $secret = '{secret}';
    $consumer = new OAuthConsumer($key, $secret);//defined in OAuth lib
    $accessToken = json_decode(file_get_contents('accessToken.txt'));//assuming you already have access token
    $guid = '{guid of app user}';
    $url = sprintf(
    "http://%s/v1/user/%s/presence/presence",
    'social.yahooapis.com',
    $guid
    );
    //sign request
    $request = OAuthRequest::from_consumer_and_token(//defined in OAuth lib
    $consumer,
    $accessToken,
    'PUT',
    $url,
    array());
    $request->sign_request(
    new OAuthSignatureMethod_HMAC_SHA1(),
    $consumer,
    $accessToken
    );
    //define headers
    $headers = array("Accept: application/json");
    $headers[] = $request->to_header();
    $headers[] = "Content-type: application/json";
    //define new status and format it for request
    $status = 'and the time is ... '.time();
    $presence = array("status" => $status);
    $content = json_encode($presence);
    //exec request
    $ch = curl_init($url);
    $options = array(
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_POSTFIELDS => $content,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_TIMEOUT => 3
    );
    curl_setopt_array($ch, $options);
    $resp = curl_exec($ch);
    curl_close($ch);

    For future reference, please indicate what language you're using, if you're building a desktop or web app, if you're using the Y! SDK, and some sample code that reproduces the problem.

    Please post back if you have any further questions.

    Erik



    QUOTE (Jono @ Jan 26 2009, 11:02 PM) <{POST_SNAPBACK}>
    Hi
    I was able to use all Social APIs including GET STATUS API. But for setting the status, when i use PUT Method, it says please provide valid credentials.
    Kindly explain what could be the problem. I'm passing all the Oauth Parameters required but still don't know why it's not working.
    Kindly suggest

    THANKS
    ANKIT
    0
  • Hi

    im using JAVA..
    It doesn't say signature_invalid when calling all other apis, then why it says it's invalid when PUT status is used?
    Also can we use PLAINTEXT signature method in PUT status API
    0
  • THIS IS REALLY STRANGE OF YAHOO!
    only during status calls it asks for LINKED parameters, ie. parameters should be alphabetically arranged.
    I used linked hash map and it worked.
    It worked but now it is entering null value in my status.
    WHAT Request PARAMETER do i have to add with my call to set the status text. Right now i'm adding 'status' parameter and it's not working.
    0
  • what i understand is that we have to pass status in the jason format ..
    DOUBTS:
    1. Do i have to pass it with a seperate header.. if yes what are the name and values of this header. ?
    2. exactly what thing i have to pass (like json or json encoded etc) ?
    3. Can i pass it in the parameters itself ?
    -1
  • QUOTE (Jono @ Feb 12 2009, 01:40 AM) <{POST_SNAPBACK}>
    what i understand is that we have to pass status in the jason format ..
    DOUBTS:
    1. Do i have to pass it with a seperate header.. if yes what are the name and values of this header. ?
    2. exactly what thing i have to pass (like json or json encoded etc) ?
    3. Can i pass it in the parameters itself ?



    The http body should contain a JSON string representing the status. It will not accept the status in the query string or in a header.

    ie:

    {"status":"myNewStatus"}
    0
  • I am using java oauth libraries to try and update the user status. My code works for "GET", so i end up with the user's status.
    However, when i do a 'PUT', i get this exception

    SEVERE: params: {<?xml version='1.0' encoding='utf-8'?>
    <error xmlns='http://yahooapis.com/v1/base.rng'
    xml:lang='en'>
    <description>405 Method Not Allowed</description>
    <detail>Method not allowed for this URI
    </detail>
    </error>
    , HTTP response=HTTP/1.1 405 Method Not Allowed
    Date: Wed, 11 Mar 2009 11:20:01 GMT
    Content-Type: application/xml
    Content-Language: en
    Allow: OPTIONS, HEAD, GET, PUT
    Age: 0
    Transfer-Encoding: chunked
    Connection: keep-alive
    Via: HTTP/1.1 r1.ycpi.uls.yahoo.net (YahooTrafficServer/1.17.9 [c s f ])
    Server: YTS/1.17.9

    <?xml version='1.0' encoding='utf-8'?>
    <error xmlns='http://yahooapis.com/v1/base.rng'
    xml:lang='en'>
    <description>405 Method Not Allowed</description>
    <detail>Method not allowed for this URI
    </detail>
    </error>
    , URL=http://social.yahooapis.com/v1/user/J7MKWLXDJUPVFPSB43CX4URHCQ/presence/presence, HTTP status=405, HTTP request headers=POST /v1/user/J7MKWLXDJUPVFPSB43CX4URHCQ/presence/presence
    User-Agent: Jakarta Commons-HttpClient/3.1
    Host: social.yahooapis.com
    Content-Length: 1179
    Content-Type: application/x-www-form-urlencoded
    }


    I am passing the status data in as parameters along side the OAuth parameters into an OAuthMessage.

    final Map<String, String> values = new LinkedHashMap<String, String>();
    values.put("starttime", "2009-03-11T04:13:12Z");
    values.put("endtime", "");
    values.put("status", "doing nothing");

    Can someone tell me where im going wrong?

    thanks
    0
  • Hi MaryS,

    Can you please post the chunk where you're setting the PUT method...I'm seeing some POST info there.

    Jon

    QUOTE (MaryS @ Mar 11 2009, 03:24 AM) <{POST_SNAPBACK}>
    I am using java oauth libraries to try and update the user status. My code works for "GET", so i end up with the user's status.
    However, when i do a 'PUT', i get this exception

    SEVERE: params: {<?xml version='1.0' encoding='utf-8'?>
    <error xmlns='http://yahooapis.com/v1/base.rng'
    xml:lang='en'>
    <description>405 Method Not Allowed</description>
    <detail>Method not allowed for this URI
    </detail>
    </error>
    , HTTP response=HTTP/1.1 405 Method Not Allowed
    Date: Wed, 11 Mar 2009 11:20:01 GMT
    Content-Type: application/xml
    Content-Language: en
    Allow: OPTIONS, HEAD, GET, PUT
    Age: 0
    Transfer-Encoding: chunked
    Connection: keep-alive
    Via: HTTP/1.1 r1.ycpi.uls.yahoo.net (YahooTrafficServer/1.17.9 [c s f ])
    Server: YTS/1.17.9

    <?xml version='1.0' encoding='utf-8'?>
    <error xmlns='http://yahooapis.com/v1/base.rng'
    xml:lang='en'>
    <description>405 Method Not Allowed</description>
    <detail>Method not allowed for this URI
    </detail>
    </error>
    , URL=http://social.yahooapis.com/v1/user/J7MKWLXDJUPVFPSB43CX4URHCQ/presence/presence, HTTP status=405, HTTP request headers=POST /v1/user/J7MKWLXDJUPVFPSB43CX4URHCQ/presence/presence
    User-Agent: Jakarta Commons-HttpClient/3.1
    Host: social.yahooapis.com
    Content-Length: 1179
    Content-Type: application/x-www-form-urlencoded
    }


    I am passing the status data in as parameters along side the OAuth parameters into an OAuthMessage.

    final Map<String, String> values = new LinkedHashMap<String, String>();
    values.put("starttime", "2009-03-11T04:13:12Z");
    values.put("endtime", "");
    values.put("status", "doing nothing");

    Can someone tell me where im going wrong?

    thanks
    0
  • Hi here is a snippet of my code


    final String sessionKey = credentials.getKey();
    final String sessionSecret = credentials.getSecret();
    final OAuthRequestConfiguration requestConfig = new OAuthRequestConfiguration(
    "PUT", sessionKey, sessionSecret);
    final String guid = credentials.getUserId();

    String requestUri = "http://social.yahooapis.com/v1/user/{guid}/presence/presence";
    requestUri = requestUri.replace("{guid}", guid);

    final Map<String, String> values = new LinkedHashMap<String, String>();
    values.put("starttime", "2009-03-11T04:13:12Z");
    values.put("endtime", "");
    values.put("status", "doing nothing");

    log.info("Request URI: " + requestUri);

    try {
    final String rawResponse = OAuthRequestBroker.request(
    providerConfig, requestConfig, requestUri, values);
    return rawResponse;
    } catch (Throwable ex) { }


    QUOTE (Jon @ Mar 11 2009, 12:26 PM) <{POST_SNAPBACK}>
    Hi MaryS,

    Can you please post the chunk where you're setting the PUT method...I'm seeing some POST info there.

    Jon
    0
  • Ok i managed to update the status. The problem was the OAuth libraries, they
    did not support the PUT operation. So i basically got the latest ones and it works.
    However when i put my new status eg 'thello his is a new status', this updates, however
    when i check my profile page it says '“hello%20this%20is%20a%20new%20status” .
    it seems as though it is not decoded on the yahoo end?
    any ideas?

    QUOTE (MaryS @ Mar 12 2009, 02:32 AM) <{POST_SNAPBACK}>
    Hi here is a snippet of my code


    final String sessionKey = credentials.getKey();
    final String sessionSecret = credentials.getSecret();
    final OAuthRequestConfiguration requestConfig = new OAuthRequestConfiguration(
    "PUT", sessionKey, sessionSecret);
    final String guid = credentials.getUserId();

    String requestUri = "http://social.yahooapis.com/v1/user/{guid}/presence/presence";
    requestUri = requestUri.replace("{guid}", guid);

    final Map<String, String> values = new LinkedHashMap<String, String>();
    values.put("starttime", "2009-03-11T04:13:12Z");
    values.put("endtime", "");
    values.put("status", "doing nothing");

    log.info("Request URI: " + requestUri);

    try {
    final String rawResponse = OAuthRequestBroker.request(
    providerConfig, requestConfig, requestUri, values);
    return rawResponse;
    } catch (Throwable ex) { }
    0
  • hmmm are you setting the content type for the request? In the case of the PHP SDK it's set to "application/json". If the exploration of the content type doesn't produce results, can you try adding HTML entities for the space (&nbsp;). I'm thinking that the string is being url encoded and then output as plain text (which should be the content type setting).

    - Jon

    QUOTE (MaryS @ Mar 13 2009, 01:22 AM) <{POST_SNAPBACK}>
    Ok i managed to update the status. The problem was the OAuth libraries, they
    did not support the PUT operation. So i basically got the latest ones and it works.
    However when i put my new status eg 'thello his is a new status', this updates, however
    when i check my profile page it says '“hello%20this%20is%20a%20new%20status” .
    it seems as though it is not decoded on the yahoo end?
    any ideas?
    0
  • hey, just a quick note, maybe it will help somebody else as well -

    in the second message, in the PHP example, with CURL, the guy uses TXT file called "accessToken.txt".
    you need to make it first.

    I made it by adding these few lines in file /lib/Yahoo.inc,

    after the line ~595, function name "function initSession",
    when you get the $accessToken variable for the first time, you should JSON it and write to a txt file (or a database, if you prefer, like I do):

    so, when you see this line:

    // Found an OAuth Access Token session.
    $accessToken = $sessionStore->fetchAccessToken();

    just add these few lines bellow:

    /* dootzky save-access-token hack */
    $jsoned_token = json_encode($accessToken);
    $handle = fopen('accessToken.txt', 'w+');
    fwrite($handle, $jsoned_token);
    fclose($handle);

    and that's it! that's how you get the file which you can use to JSON_DECODE later in the example that the guy in the second post was talking about.
    and it works! :)[www.dootkzy.com / www.dule.rs ]
    0
  • How to use this status api and how to run this api ?

    -1
This forum is locked.

Recent Posts

in Status