Welcome Developers!

in

Welcome!

in

PHP OAuth extension

Last post 09-27-2010 2:48 PM by Joel. 23 replies.
Page 1 of 2 (24 items) 1 2 Next >
Sort Posts: Previous Next
  • 02-22-2010 6:57 AM

    • Krowa
    • Not Ranked
    • Joined on 02-09-2010
    • Posts 7

    PHP OAuth extension

    Hello.

    I'm developing new app in PHP. I have OAuth extension installed and I can succefully make GET requests but I can't use any PUT request. :(

    Normally (and by that I mean something like for example Twitter) I can use code like this:

    $oauth->fetch(MYSPACE_SET_MOOD,$args,OAUTH_HTTP_METHOD_PUT,$headers);

    And $args = Array('mood'=>'66'); But I found that this won't work here.I think it's because I can't put anything in $args:

    http://wiki.developer.myspace.com/index.php?title=PUT_v1_users_userId_mood

    But how can I add anything to the request body when there is no other parameters in $oauth->fetch?

     

    Edit: I forgot to link to PHP OAuth: http://pl.php.net/manual/pl/oauth.fetch.php

    Filed under: , , ,
  • 02-22-2010 5:08 PM In reply to

    Re: PHP OAuth extension

     I believe I have seen this issue before. If you use our PHP SDK and oauth.php file, does this problem go away? If you can get a Wireshark capture of this api request and subsequent rejection, that'd be helpful. Just send the six digit appID, consumer key/secret to developerrelations@myspace-inc.com.

     

    thanks,

    Joel

  • 02-23-2010 4:38 AM In reply to

    • Krowa
    • Not Ranked
    • Joined on 02-09-2010
    • Posts 7

    Re: PHP OAuth extension

    Right now I can't get your SDK to work at all. :/

    All I'm getting is this:

    stdClass Object(    
    [statusCode] => 401
    [statusDescription] => Invalid digital signature for base string: "GET&http%3A%2F%2Fapi.myspace.com%2Fv1%2Fusers%2F521711695%2Fmood.json&oauth_consumer_key%3D28ea58202cb6471695584d6db51d8305%26oauth_nonce%3Dda7ce4df6cd1975f2f525d648da2e242%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1266925896%26oauth_token%3DEcybXWDRDpyCFrQ3jSiWkcnyVPDydOhEjV95wB1khJLeeDw8PL8Imk5qm2GL0F8eXejgJZnGJ%252BgJrZIOsRRFjTT4Cg51YoVGcG1BQ4J%252FBy8%253D%26oauth_version%3D1.0"
    )

    And only thing that I wanted was getting mood from my account. Funny part: I can get mood using your web tool with same data.

    I can't use Wireshark with PHP extension because it's on remote server and don't have oauth on my local sever. :( All I can't get with OAuthException are HTTP codes and there are few of them: 401, 405 and sometimes 411, depending on variable combination...

     If there are some other info that I can get for you than tell me and I will do my best to get them. ;)

     

    Edit: I don't know why I didn't put this in a first place:

    Error when $args is just string (it looks exactly the same when $args is array or json):

     

    exception 'OAuthException' with message 'Invalid auth/bad request (got a 405, expected HTTP/1.1 20X or a redirect)' in ./updateMood.php:26
    Stack trace:
    #0 ./updateMood.php(26): OAuth->fetch('http://api.mysp...', 'mood=66', 'PUT')
    #1 ./start_conn.php(18): include_once('/srv/www/social...')
    #2 {main}

     

    When I change PUT to POST I'm getting 401. I tried to add additional headers Content-Type and Content-Length but this will generate Apache error: Premature end of script headers. I'm pretty sure Content-Length has proper value. Also I tried to add Accept: application/json but this didn't get me anywhere too...

    Filed under: , , ,
  • 02-23-2010 2:41 PM In reply to

    Re: PHP OAuth extension

    The first easy thing you can try is to change your consumer key and secret in the app settings page. See if that makes a difference. It will be hard to troubleshoot without a Wireshark capture, but there is a tool on Firefox called "Poster" which you can use to make GET/POST/PUT calls and Wireshark capture those. Oauth should work properly in our PHP SDK, but I would need to see the whole sequence of calls or at least a capture of this signature failure via Poster and Wireshark.

     

    thanks,

    Joel

  • 02-24-2010 1:24 AM In reply to

    • Krowa
    • Not Ranked
    • Joined on 02-09-2010
    • Posts 7

    Re: PHP OAuth extension

    I tried to change key and secret but it didn't work. :(

    But I finally found oauth.dll for win apache, so I ccan monitor what is going on. :) I didn't use Wireshark because I find Microsoft Network Monitor a little bit more easy to use.

    [Here was some info but it's not up to date...]

     Right now I've manage to get User Data and use GET to fetch some additional info about specific user. But I still can't update anything. This is what I get while using PUT:

    REQUEST:

    - Http: Request, PUT /v1/users/521711695/mood.json
        Command: PUT
      - URI: /v1/users/521711695/mood.json?oauth_consumer_key=28ea58202cb6471695584d6db51d8305&oauth_signature_method=HMAC-SHA1&oauth_nonce=66494b84fc7d64f209.70311100&oauth_timestamp=1267006589&oauth_version=1.0&oauth_token=3BdEbJT%2BUhhOfY0dy4D80qI2i4PiZj5KxDe5XpND
         Location: /v1/users/521711695/mood.json
         oauth_consumer_key: 28ea58202cb6471695584d6db51d8305
         oauth_signature_method: HMAC-SHA1
         oauth_nonce: 66494b84fc7d64f209.70311100
         oauth_timestamp: 1267006589
         oauth_version: 1.0
         oauth_token: 3BdEbJT%2BUhhOfY0dy4D80qI2i4PiZj5KxDe5XpNDR%2BEv17TVDhxW27qDpJFT8lxLs0ycTZjxO73KGaBzZjxuVXydUtc1UbhfJ8dYT1xqS%2FQ%3D
         oauth_signature: 0MRMjwTAKGqYkLD%2FnMwZ5GWotHE%3D
        ProtocolVersion: HTTP/1.1
        Host:  api.myspace.com
        Accept:  */*
        ContentLength:  14
      - ContentType:  application/x-www-form-urlencoded
         MediaType:  application/x-www-form-urlencoded
        HeaderEnd: CRLF
        payload: HttpContentType =  application/x-www-form-urlencoded

    RESPONSE:

    - Http: Response, HTTP/1.1, Status Code = 405, URL: /v1/users/521711695/mood.json
        ProtocolVersion: HTTP/1.1
        StatusCode: 405, Method not allowed
        Reason: Method Not Allowed
        Cache-Control:  private
        ContentLength:  45
      - ContentType:  text/html; charset=UTF-8
         MediaType:  text/html; charset=UTF-8
        Server:  Microsoft-IIS/6.0
        XPoweredBy:  ASP.NET
        Set-Cookie:  MSCulture=IP=194.181.152.194&IPCulture=pl-PL&PreferredCulture=pl-PL&PreferredCulturePending=&Country=UEw=&ForcedExpiration=634025745902064040&timeZone=0&myStuffDma=&myStuffMarket=&USRLOC=QXJlYUNvZGU9MCZDaXR5PVdyb2NsYXcmQ291bnRyeUNvZGU9UEwmQ291bnR
        Set-Cookie:  ASP.NET_SessionId=aeu24y45japrlb55r0csb4nl; path=/; HttpOnly
        X-Server:  f4baf9d36bd53bb58172761b61cfdaaff47bc973d59f3a01
        Set-Cookie:  SessionDDF1=c59bfad1cf8a31fe23a99e6f7c93dd6a4d7543a8f7143c5c; domain=.myspace.com; path=/
        Set-Cookie:  SessionDDF2=4ddee654baa9abb0315db5682396b5b2770d5cfec79ab99a; domain=.myspace.com; path=/; expires=Tuesday, 24-Aug-10 10:16:30 GMT
        Date:  Wed, 24 Feb 2010 10:16:29 GMT
        HeaderEnd: CRLF
      - payload: HttpContentType =  text/html; charset=UTF-8
         HtmlElement: {"statusCode":"405","statusDescription":null}

     And when I try to change to POST I get this:

    HTTPPayloadLine: {"statusCode":"401","statusDescription":"Invalid digital signature for base string: \"POST&http%3A%2F%2Fapi.myspace.com%2Fv1%2Fusers%2F521711695%2Fmood.json&%3D%257B%2522mood%2522%253A%2522100%2522%257D%26oauth_consumer_key%3D28ea58202cb64716 

    In response to:

    - Http: Request, POST /v1/users/521711695/mood.json
    Command: POST
    - URI: /v1/users/521711695/mood.json?oauth_consumer_key=28ea58202cb6471695584d6db51d8305&oauth_signature_method=HMAC-SHA1&oauth_nonce=120024b851c8e93e7c8.92703687&oauth_timestamp=1267014798&oauth_version=1.0&oauth_token=3BdEbJT%2BUhhOfY0dy4D80qI2i4PiZj5KxDe5XpN
    Location: /v1/users/521711695/mood.json
    oauth_consumer_key: 28ea58202cb6471695584d6db51d8305
    oauth_signature_method: HMAC-SHA1
    oauth_nonce: 120024b851c8e93e7c8.92703687
    oauth_timestamp: 1267014798
    oauth_version: 1.0
    oauth_token: 3BdEbJT%2BUhhOfY0dy4D80qI2i4PiZj5KxDe5XpNDR%2BEv17TVDhxW27qDpJFT8lxLs0ycTZjxO73KGaBzZjxuVXydUtc1UbhfJ8dYT1xqS%2FQ%3D
    oauth_signature: futZxvnQUmQcPWqWMb%2B7aHq9gMQ%3D
    ProtocolVersion: HTTP/1.1
    Host: api.myspace.com
    Accept: application/json
    ContentLength: 8
    - ContentType: application/x-www-form-urlencoded
    MediaType: application/x-www-form-urlencoded
    HeaderEnd: CRLF
    - payload: HttpContentType = application/x-www-form-urlencoded
    mood: 100
     
    I used here json extension but with default results are the same.
  • 02-24-2010 3:09 PM In reply to

    Re: PHP OAuth extension

     For your POST issue, is that the entire base string that was returned in the 401 response, or did you cut it off? If oauth signatures are not matching, it could mean the percent encoding is incorrect. Can you try using the Poster extension for Firefox and let me know if sending these params through results in the same error?

     

    thanks,

    Joel

  • 02-25-2010 12:14 AM In reply to

    • Krowa
    • Not Ranked
    • Joined on 02-09-2010
    • Posts 7

    Re: PHP OAuth extension

    Hmm...funny thing. Details window didn't show entire string like hex window...So here you go - entire response for POST method:

    - Http: Response, HTTP/1.0, Status Code = 401, URL: /v1/users/521711695/mood.json
        ProtocolVersion: HTTP/1.0
        StatusCode: 401, Unauthorized
        Reason: Unauthorized
        Cache-Control:  private
        ContentLength:  493
      - ContentType:  application/json; charset=utf-8
         MediaType:  application/json; charset=utf-8
        Server:  Microsoft-IIS/6.0
        XPoweredBy:  ASP.NET
        Set-Cookie:  MSCulture=IP=79.110.194.69&IPCulture=pl-PL&PreferredCulture=pl-PL&PreferredCulturePending=&Country=UEw=&ForcedExpiration=634026532310050805&timeZone=0&myStuffDma=&myStuffMarket=&USRLOC=QXJlYUNvZGU9MCZDaXR5PVdyb2NsYXcmQ291bnRyeUNvZGU9UEwmQ291bnRye
        Set-Cookie:  ASP.NET_SessionId=jovxmk45dimcp245amdwepi1; path=/; HttpOnly
        X-Server:  8e88a4ee0141a0f02bb4ae5086552464913511b3a5ab0046
        Set-Cookie:  SessionDDF1=211ec60ab3af63a833d04f4d0eb26f7379c673c7bb96d42d; domain=.myspace.com; path=/
        Set-Cookie:  SessionDDF2=8d39f00fc5559ea5a45a6e0a0b7f005f62e4d7c1ad0a67cb; domain=.myspace.com; path=/; expires=Wednesday, 25-Aug-10 08:07:11 GMT
        Date:  Thu, 25 Feb 2010 08:07:10 GMT
        X-Cache:  MISS from localhost
        X-Cache-Lookup:  MISS from localhost:3128
        Via:  1.0 localhost (squid/3.0.STABLE8)
        ProxyConnection:  close
        HeaderEnd: CRLF
      - payload: HttpContentType =  application/json; charset=utf-8
         HTTPPayloadLine: {"statusCode":"401","statusDescription":"Invalid digital signature for base string: \"POST&http%3A%2F%2Fapi.myspace.com%2Fv1%2Fusers%2F521711695%2Fmood.json&mood%3D66%26oauth_consumer_key%3D28ea58202cb6471695584d6db51d8305%26oauth_nonce%3D64394b862fae8e5c03.63489330%26oauth_signature_method%3DHMA

    Now I'll try that Poster extension, although I'm not sure how to use it, so first I need to learn it. ;)

    Edit: I don't know why but I can't get Poster to send any parameters (I think I'm doing something wrong but I don't know what exactly). First of all it doesn't sends HeaderEnd and I can't put it myself because this way it lands somewhere between headers, not on the end. And in this way I only get GET.

    Edit2: I've changed json to xml in Poster and then I've got same 401 as above:

    - Http: Response, HTTP/1.0, Status Code = 401, URL: /v1/users/521711695/mood
        ProtocolVersion: HTTP/1.0
        StatusCode: 401, Unauthorized
        Reason: Unauthorized
        Cache-Control:  private
        ContentLength:  548
      - ContentType:  application/xml; charset=utf-8
         MediaType:  application/xml; charset=utf-8
        Server:  Microsoft-IIS/6.0
        XPoweredBy:  ASP.NET
        X-Server:  723a40be282090752ad6b2698c03fde05ca2865477256c86
        Date:  Thu, 25 Feb 2010 10:03:17 GMT
        X-Cache:  MISS from localhost
        X-Cache-Lookup:  MISS from localhost:3128
        Via:  1.0 localhost (squid/3.0.STABLE8)
        ProxyConnection:  close
        HeaderEnd: CRLF
      - payload: HttpContentType =  application/xml; charset=utf-8
       - Xml:
          XmlPropertiesInitiator:
        - Element: XmlElement:<error>
         + STag: <error xmlns="api-v1.myspace.com">
         + Element: XmlElement:<statuscode> - 401
         - Element: XmlElement:<statusdescription>
          + STag: <statusdescription>
            Content: Invalid digital signature for base string: "POST&amp;http%3A%2F%2Fapi.myspace.com%2Fv1%2Fusers%2F521711695%2Fmood&amp;oauth_consumer_key%3D28ea58202cb6471695584d6db51d8305%26oauth_nonce%3D37344b864a156a33e0.08082301%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1267091989%26oauth_token%3Dsplcscl299z4tkqqujAU5yHYYU2D3u5ZsJ3YqChvGbckd5ox4pP63Pyc48rmV6HoF8zHT3ksgNIHqRPKo6zFX3sIBkssH2%252Fifw0iN2Tlwq8%253D%26oauth_version%3D1.0"
          + ETag: </statusdescription>
         + ETag: </error>

     In response to:

    - Http: Request, POST /v1/users/521711695/mood
        Command: POST
      - URI: /v1/users/521711695/mood?oauth_consumer_key=28ea58202cb6471695584d6db51d8305&oauth_signature_method=HMAC-SHA1&oauth_nonce=37344b864a156a33e0.08082301&oauth_timestamp=1267091989&oauth_version=1.0&oauth_token=splcscl299z4tkqqujAU5yHYYU2D3u5ZsJ3YqChvGbckd5o
         Location: /v1/users/521711695/mood
         oauth_consumer_key: 28ea58202cb6471695584d6db51d8305
         oauth_signature_method: HMAC-SHA1
         oauth_nonce: 37344b864a156a33e0.08082301
         oauth_timestamp: 1267091989
         oauth_version: 1.0
         oauth_token: splcscl299z4tkqqujAU5yHYYU2D3u5ZsJ3YqChvGbckd5ox4pP63Pyc48rmV6HoF8zHT3ksgNIHqRPKo6zFX3sIBkssH2%2Fifw0iN2Tlwq8%3D
         oauth_signature: O%2F5FrteR8%2B8nZX5ndcIWpYreSo0%3D
        ProtocolVersion: HTTP/1.1
        Host:  api.myspace.com
        UserAgent:  Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.2) Gecko/20100115 Firefox/3.6
        Accept:  application/json
        Accept-Language:  pl,en-us;q=0.7,en;q=0.3
        Accept-Encoding:  gzip,deflate
        Accept-Charset:  ISO-8859-2,utf-8;q=0.7,*;q=0.7
        Keep-Alive:  115
        Connection:  keep-alive
      - ContentType:  application/x-www-form-urlencoded; charset=UTF-8
         MediaType:  application/x-www-form-urlencoded; charset=UTF-8
        ContentLength:  8
        Cookie:  SessionDDF2=3cf231b87da156158a5dfd42d0b2b6a80b4f2e2344284e12; __utma=144631658.307998758.1267084837.1267084837.1267084837.1; __utmz=144631658.1267084837.1.1.utmcsr=home.myspace.com|utmccn=(referral)|utmcmd=referral|utmcct=/index.cfm; MSCulture=IP=79.
  • 02-25-2010 1:39 PM In reply to

    Re: PHP OAuth extension

     Krowa,

    Running your request through my validator, I can see that the oauth signatures do not match up, so the error makes sense. The nonce you have has a period in it. I don't think that's the cause but I have never seen that before. I continue to investigate.

    I'd also be curious to see if using the newer 0.9 API would make any difference:

    http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_StatusMood

     

    thanks,

    Joel

  • 02-25-2010 1:57 PM In reply to

    Re: PHP OAuth extension

    Krowa, what is the bigger picture here? What else will your app need to do? I have a PHP library for MySpace I wrote that I was using internally (switched to Python now). I could add status set / get to it if that is all you need.
  • 02-25-2010 2:38 PM In reply to

    Re: PHP OAuth extension

    Just in case this is useful, I managed to do a PUT request to change mood.

    PUT /v1/users/85628343/mood?oauth_consumer_key=http%3A%2F%2Fwww.myspace.com%2F457168699&oauth_token=&oauth_nonce=0.92087400%2012671371221215280272&oauth_timestamp=1267137122&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_signature=J7xmrmxQp489VJF4iU6phkD0HUQ%3D

    And in the body part I put "mood=100". Since this is just a test app for API tests, I can reveal my keys:

    $CONSUMER_KEY = 'http://www.myspace.com/457168699';
    $CONSUMER_SECRET = '3a7dc34fa49c457986d1e7befe440d34';


    You can try setting my mood and see if it works. If you copy my nonce too, you should be able to make an identical call since the consumer key, secret key and everything is the same (unless you have a bug). My uid is 85628343.

    Here is the whole output from my program: http://pastebin.ca/1810886
    Here is the program: http://pastebin.ca/1810891
    Here is my MySpaceAPI (no longer maintained) required by that program: http://pastebin.ca/1810894


    With these you should be able to replicate my call.
  • 02-25-2010 2:45 PM In reply to

    Re: PHP OAuth extension

     Actually, I am seeing the oauth_signature is not in the failing base string. Checking to see if other things are also missing..

     Bemmu's nonce contains a period too, convincing me that is not problematic.

     

    -Joel

  • 02-26-2010 1:01 AM In reply to

    • Krowa
    • Not Ranked
    • Joined on 02-09-2010
    • Posts 7

    Re: PHP OAuth extension

    Joel:

    I'd also be curious to see if using the newer 0.9 API would make any difference:

    http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_StatusMood

     

    So...Up to your post I was using this:

    http://wiki.developer.myspace.com/index.php?title=PUT_v1_users_userId_mood

    because it looked more...hmm...natural for me. ;) I don't know why but in my head OpenSocial was somehow equivalent with OpenID. ;)

    But I tried this new method now and..........it works! Of course I have to look more closly on what can I do with it but I succefully managed to add mood into my account.

     

    Thanks for your help. :) If I find some other problems I'll definitely get back here. ;)

  • 02-26-2010 2:15 PM In reply to

    Re: PHP OAuth extension

     Sounds good. Thanks for the update.

     

    -Joel

  • 07-17-2010 9:00 AM In reply to

    Re: PHP OAuth extension

     Can anybody share a good example of updating stream on MySpace using oAuth extension? I put something together, but it is not working just yet.

    function ms1(){
             $message = "test";
             $user_id='518002158';

            try {

              $oauth = new OAuth(MYSPACE_OAUTH_CONSUMER_KEY,MYSPACE_OAUTH_CONSUMER_SECRET,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_FORM);
              //$oauth->enableDebug();  // This will generate debug output in your error_log
              $access_token_info = unserialize(file_get_contents(OAUTH_TMP_DIR . "/myspace_access_token"));

                // We use the stored access token
              $oauth->setToken($access_token_info['oauth_token'],$access_token_info['oauth_token_secret']);
              $args = array('content'=>'test1','title'=>'test1','body'=>'test1');
              $oauth->fetch("http://api.myspace.com/v1/users/".$user_id."/mood.json",$args,OAUTH_HTTP_METHOD_PUT);
              $json = json_decode($oauth->getLastResponse(),true);
              if(isset($json['id'])) {
                $this->create_box('tw');
                d($json);
                //$this->db->query('UPDATE ad_master SET social_net = social_net | 2 WHERE id='.$this->ad->id);
              } else {
                // It failed
                d($json);
                echo "failes";
              }

            } catch(OAuthException $E) {
              //print_r($E);
            }
         }

  • 07-19-2010 2:56 PM In reply to

    Re: PHP OAuth extension

     I believe I responded to this question on a separate thread. Is this an offsite app? Can you send a Wireshark http capture of the request/failure to developerrelations@myspace-inc.com?

     

    thanks,

    Joel

Page 1 of 2 (24 items) 1 2 Next >