I have a program which will do automatic checkins on Foursquare. It was working fine up until about a couple days ago when it started returning Response [403]. What is weird is I found some sample code to do the same thing via PHP and it is working fine.
The same Oauth token is being used for both the PHP and Python version.
PHP Version:
<?php
$fields_string = http_build_query(array(
'oauth_token'=>'***REDACTED***',
'venueId'=> '4e769e971838f9188a5e2a03',
'v'=>'20180801',
'broadcast'=>'public'
));
$url = "https://api.foursquare.com/v2/checkins/add";
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$checkin = curl_exec($ch);
// Check if any error occured
if(curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
//close connection
curl_close($ch);
$json=json_decode($checkin);
echo $checkin;
echo $json->meta->code;
?>
Python Version:
import json, requests
checkinURL = 'https://api.foursquare.com/v2/checkins/add'
checkinParams = dict(
oauth_token = '***REDACTED***',
venueId = '4e769e971838f9188a5e2a03',
v = 20180801,
broadcast = 'public'
)
checkin = requests.post(url=checkinURL, params=checkinParams)
print (checkin)
Here's the debug from Python:
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.foursquare.com:443
send: b'POST /v2/checkins/add?oauth_token=***REDACTED***&ll=21.281656%2C-157.677465&limit=1&venueId=4e769e971838f9188a5e2a03&shout=Testing&v=20180801&broadcast=public HTTP/1.1\r\nHost: api.foursquare.com\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n'
reply: 'HTTP/1.1 403 Unauthorized\r\n'
header: Server: Varnish
header: Retry-After: 0
header: Content-Length: 2713
header: Content-Type: text/html
header: Accept-Ranges: bytes
header: Date: Mon, 29 Oct 2018 06:46:48 GMT
header: Via: 1.1 varnish
header: Connection: close
header: X-Served-By: cache-bur17527-BUR
header: X-Cache: MISS
header: X-Cache-Hits: 0
DEBUG:urllib3.connectionpool:https://api.foursquare.com:443 "POST /v2/checkins/add?oauth_token=***REDACTED***&ll=21.281656%2C-157.677465&limit=1&venueId=4e769e971838f9188a5e2a03&shout=Testing&v=20180801&broadcast=public HTTP/1.1" 403 2713
<Response [403]>