开发者

Can you retrieve your Skype status using JSONP?

Does anyo开发者_运维技巧ne know of a URL to get your Skype status using JSONP?

I've only found an XML status URL so far (http://mystatus.skype.com/username.xml).

(I'm trying to query Skype using AJAX. Yes, I could use a server-side proxy script to beat the cross-domain limits, but a direct call would be awesome.)

Simon.


Well apparently you can get a text-only version of the status by changing the extension to .txt:

http://mystatus.skype.com/username.txt

It will return "Online" or "Offline". About the Cross-domain AJAX, you can only do it via server and direct call is definitely not allowed.


You might change the headline to 'JSONP' instead of JSON. That's what you want.

JSONP hijacks cross domain fetches like this to work, without server proxies, by carrying the data in fetches. It's like the most hackish useful technology I come to mind, right now. :)

I nagged Skype about this - the easiest way out would be for their servers to have an official, documented JSONP interface. I hope they'll do that.

In the mean time, this is how I got the problem solved:

  • Placed this PHP script on my server, alongside the usual HTML: http://benalman.com/projects/php-simple-proxy/

  • Edited the configuration of it like so:

$enable_native   = true;
$valid_url_regex = '/^http:\/\/mystatus\.skype\.com\/myuserid.*/';

This allows it to fetch (via curl running on the server) the mystatus.skype.com/myuserid.num (or .txt) information.

  • Fetching from JS with URL:
ba-simple-proxy.php?url=http%3A%2F%2Fmystatus.skype.com%2Fmyuserid.num&mode=native&full_status=1

That's it. Pheeew... :)


Also you can retrieve it using PHP

function getSkypeStatus($username) {
    $data = file_get_contents('http://mystatus.skype.com/' . urlencode($username) . '.xml');

    return strpos($data, '<presence xml:lang="en">Offline</presence>') ? 'Offline' : 'Online';
}

OR

function getSkypeStatus($username) {
    $data = file_get_contents('http://mystatus.skype.com/' . urlencode($username) . '.xml');
    preg_match('@<presence xml:lang="en">(.*?)</presence>@i', $data, $match);

    return isset($match[1]) ? $match[1] : 'Error retrieving status';
} 

Cheers!

Thanks to Bradgrafelman from - http://www.phpbuilder.com/board/showthread.php?t=10361050

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜