Foursquare通过curl php添加场地帖子

时间:2011-03-24 07:21:36

标签: php curl oauth foursquare

有没有人试图在php中使用curl方法添加新场地?以下是我的代码:

<?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网站。谢谢。

1 个答案:

答案 0 :(得分:-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(app key),oauth_token和v。