tags:

views:

83

answers:

2

I am experimenting with differnt API's of websites right now because I am building my own API for site, On bebo.com through there API they have a php cient which passes a key and secret that the owner of the app has. you then have a client library with a bunch of methods/functions you can call, all of the methods work like this:

  public function score_getHigh($uid='', $name='') {
    return $this->execute('score.getHigh', array('member_id' => $uid, 'name' => $name));
  }

You can see they all just pass in a name of a function and put the params into an array and pass it through the execute(METHOD-NAME, METHOD PARAMS) function. This function then runs code like this

//execute function 
    //flatten array
    foreach ($params as $k => $v) {
      if (is_array($v)) {
        $params[$k] = implode(',', $v);
      }
    }

To make a list of all the functions and params to run, it then POST or GET this to the API page with CURL and this is the result that comes back below in my browser if I visit the page myself in a browser instead of letting curl post it then I view the page source of the web browser it shows this array just how I posted it in the browser,

Array
(
    [error_code] => 102
    [error_msg] => Session key invalid or no longer valid
    [request_args] => Array
        (
            [0] => Array
                (
                    [key] => v
                    [value] => 1.0
                )

            [1] => Array
                (
                    [key] => api_key
                    [value] => Qnw1Moc22Y9m3XY5zUZohbxiwfkURaPJpN3m
                )

            [2] => Array
                (
                    [key] => method
                    [value] => friends.get
                )

            [3] => Array
                (
                    [key] => call_id
                    [value] => 1262417906.33
                )

            [4] => Array
                (
                    [key] => sig
                    [value] => 18b8592f383a5f0abc332745284a0e99
                )

        )

)

So finally the question here, What kind of response is this, it's not JSON and I don't think it is XML, what would this be called and the script that is trying to get this result with CURL, how can it process this back into something to work with?

+1  A: 

From your PHP script, you should be able to do something like this:

$foo = $bebo->score_getHigh(...);
echo $foo['error_code']; // Should output 102 in this case

The response that you posted looks like the output of PHP's serialize function. That would make sense if you use Bebo's PHP client to make a request and then printed the resulting object. Bebo's service is actually returning XML to you when you make your request, as demonstrated by the example below.

$ curl http://apps.bebo.com/restserver.php?\
    v=1.0&api_key=Qnw1Moc22Y9m3XY5zUZohbxiwfkURaPJpN3m\
    &method=friends.get&call_id=1262417906.33&\
    sig=18b8592f383a5f0abc332745284a0e99

<error_response> 
  <error_code>102</error_code> 
  <error_msg>Session key invalid or no longer valid</error_msg> 
  <request_args list="true"> 
    <arg> 
      <key>v</key> 
      <value>1.0</value> 
    </arg> 
    <arg> 
      <key>api_key</key> 
      <value>Qnw1Moc22Y9m3XY5zUZohbxiwfkURaPJpN3m</value> 
    </arg> 
    <arg> 
      <key>method</key> 
      <value>friends.get</value> 
    </arg> 
    <arg> 
      <key>call_id</key> 
      <value>1262417906.33</value> 
    </arg> 
    <arg> 
      <key>sig</key> 
      <value>18b8592f383a5f0abc332745284a0e99</value> 
    </arg> 
  </request_args> 
</error_response>
William Brendel
thanks, I am trying to reproduce this for my own API so that's why I was wanting to know what the response from the server should be, so using JSON should work just as well on my own I think, thanks again
jasondavis
Consider using the HTTP `Accept` header followed by a MIME type to allow clients to specify a preferred response type. For example, `Accept: application/xml` would signal that the client wants an XML response, whereas `Accept: application/json` would indicate the client wants a JSON response. Depending on the language and framework you're using, that type of thing can be easy to implement. I am primarily a Java developer, so I'm not sure what frameworks (if any) exist for this in PHP. Good luck!
William Brendel
A: 

yep, that's a var_dump...all of this is available in your PHP