2011-03-24 57 views
0

有沒有人試圖在php中使用curl方法添加新場地?以下是我的代碼:Foursquare通過curl添加場地發佈信息php

<?php 

$post_data['name']    = 'Test Residence'; 
$post_data['address']   = '123 Test Address'; 
$post_data['crossStreet']  = ''; 
$post_data['city']    = 'Test City' 
$post_data['state']    = ''; 
$post_data['zip']    = ''; 
$post_data['phone']    = ''; 
$post_data['ll']    = '123.567,891.01112'; 
$post_data['primaryCategoryId'] = '4bf58dd8d48988d130941735'; 

foreach ($post_data as $key => $value) { 
    $post_items[] = $key . '=' . $value; 
} 

$post_string = implode ('&', $post_items); 

$curl_connection = curl_init('https://api.foursquare.com/v2/venues/add'); 

curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); 
curl_setopt($curl_connection, CURLOPT_USERAGENT, 
    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); 
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); 

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); 

$result = curl_exec($curl_connection); 

print_r(curl_getinfo($curl_connection)); 
echo curl_errno($curl_connection) . '-' . 
       curl_error($curl_connection); 

curl_close($curl_connection); 


?> 

希望你能幫助我。林不知道如果POST是成功的,但它沒有返回任何錯誤。如果場地已經更新,我嘗試檢查foursquare網站,但它沒有。謝謝。

+0

問題是什麼?順便說一句,你不需要在任何地方放置'
'。 – deceze 2011-03-24 07:27:33

+0

哦對不起。問題是我添加的場地沒有出現。即時通訊有點失去了什麼似乎是我的代碼中的問題。 :( – Mark 2011-03-24 07:37:34

回答

-1
$post_data['name']    = 'xx'; 
    $post_data['address']   = '123 Test Address'; 
    $post_data['crossStreet']  = ''; 
    $post_data['city']    = 'Test City'; 
    $post_data['state']    = ''; 
    $post_data['zip']    = ''; 
    $post_data['phone']    = ''; 
    $post_data['ll']    = '-22.423741,-45.4596028'; 
    $post_data['primaryCategoryId'] = ''; 
    $post_data['client_id']   = ''; 
    $post_data['oauth_token']  = ''; 
    $post_data['v']     = ''; 

試試吧。 Foursquare需要client_id(應用程序密鑰),oauth_token和v。