Socialcast - 使用PHP登录

时间:2012-08-15 14:15:15

标签: php api curl

我正试图从PHP访问SocialCast的API。 他们只有一个例子,用curl完成:

# Curl Example
curl -X POST -d 'password=demo&email=emily@socialcast.com' -v https://demo.socialcast.com/api/authentication.xml

如何使用PHP执行登录?

以下是API文档: http://developers.socialcast.com/api-documentation/http-basic-authentication/#authentication_api_create

1 个答案:

答案 0 :(得分:1)

您可能想要使用php curl wrapper http://php.net/manual/en/book.curl.php

这样的事情:

 $ch = curl_init("https://demo.socialcast.com/api/authentication.xml");
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, "password=demo&email=emily@socialcast.com");
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 1);
 curl_setopt($ch, CURLOPT_HEADER , 0);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
 $resp = curl_exec($ch);