9

私は優れたParseをデータストアとして使用していますが、PHPを介してアクセスする必要があります(おそらく無関係な詳細として、Facebookスクレーパーがページ上で動的に生成されたタグを認識するためにPHPを介してアクセスする必要があります)。

ParseにはRestAPIと、それらの使用方法に関する基本的な手順があります。たとえば、オブジェクトを取得するには、次のようにします。

curl -X GET \
-H "X-Parse-Application-Id:[My application ID]" \
-H "X-Parse-REST-API-Key:[My Parse Rest API key]" \
https:// api .parse.com / 1 / classes / moods /

残念ながら、これをオンラインで見たPHPCurlの例と統合する方法がわかりません。私が集める:

curl_setopt($ ch、CURLOPT_USERPWD、

..関与する可能性があります。かもしれないように:

curl_setopt($ ch、CURLOPT_URL、$ Url);

しかし、私はかなり離れている可能性があります。これを自分で理解できなくて本当に申し訳ありませんが、これまでCurl / PHPを使用したことがない人にとっては非常に混乱するため、これは依然として有効な質問だと思います。基本的に-私はParseドキュメントから引用された例をどこに置くかと同じくらい基本的な情報を探しています...

前もって感謝します

編集:

ねえ、これが私が設定した解決策です。私を正しい方向に導いてくれたdebianekに感謝します。

if ($_GET['id']) {
$imageId = $_GET['id']; 
MyApplicationId = '[ID]';
$MyParseRestAPIKey = '[API Key]';
$url = 'https://api.parse.com/1/classes/images/'.$imageId;

$headers = array(
    "Content-Type: application/json",
    "X-Parse-Application-Id: " . $MyApplicationId,
    "X-Parse-REST-API-Key: " . $MyParseRestAPIKey
);

    $handle = curl_init(); 
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);

    $data = curl_exec($handle);
curl_close($handle);

$array = json_decode($data);

$title =  $array->title;            

..等々。お役に立てば幸いです。

4

3 に答える 3

6

ヘッダーに入れます

$headers = array(
    "X-Parse-Application-Id: $MyApplicationId",
    "X-Parse-REST-API-Key: $MyParseRestAPIkey"
);

$handle = curl_init(); 
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
于 2012-07-31T10:32:50.130 に答える
4
 <?php  
 $url = 'https://api.parse.com/1/classes/GameScore';  
 $appId = 'YOUR_APP_ID';  
 $restKey = 'YOUR_REST_KEY';  
 $headers = array(  
   "Content-Type: application/json",  
   "X-Parse-Application-Id: " . $appId,  
   "X-Parse-REST-API-Key: " . $restKey  
 );  
 $objectData = '{"name":"Adarsh", "age":"26"}';  
 $rest = curl_init();  
 curl_setopt($rest,CURLOPT_URL,$url);  
 curl_setopt($rest,CURLOPT_POST,1);  
 curl_setopt($rest,CURLOPT_POSTFIELDS,$objectData);  
 curl_setopt($rest,CURLOPT_HTTPHEADER,$headers);  
 curl_setopt($rest,CURLOPT_SSL_VERIFYPEER, false);  
 curl_setopt($rest,CURLOPT_RETURNTRANSFER, true);  
 $response = curl_exec($rest);  
 echo $response;  
 print_r($response);  
 curl_close($rest);  
 ?>  
于 2014-05-02T04:57:49.757 に答える
1

すべてのオブジェクト挿入にこの関数を使用します。これは、正しいインデックスを持つ連想配列として作成する必要があるオブジェクトです。

 function insertObject($classname,$object){
 $ appId="xxxxx";
   $restKey="xxxx" 
    $url = 'https://api.parse.com/1/classes/'.$classname;
    $rest = curl_init();
        curl_setopt($rest, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($rest, CURLOPT_FRESH_CONNECT, FALSE);//use cache if available
        curl_setopt($rest, CURLOPT_TIMEOUT, 10); //10 sec timeout
        curl_setopt($rest,CURLOPT_URL,$url);
        curl_setopt($rest,CURLOPT_PORT,443);
        curl_setopt($rest,CURLOPT_POST,1);
        curl_setopt($rest,CURLOPT_POSTFIELDS,  json_encode($object));
        curl_setopt($rest,CURLOPT_HTTPHEADER,
            array("X-Parse-Application-Id: " . $appId,
                "X-Parse-REST-API-Key: " . $restKey,
                "Content-Type: application/json"));

        curl_setopt($rest, CURLOPT_SSL_VERIFYPEER, false);//to avoid certificate error
        $response = curl_exec($rest);
        echo $response ;

}
于 2014-07-19T09:54:22.210 に答える