PHP Classes

POST Runkeeper Activity

Recommend this page to a friend!

      PHP OAuth Library  >  All threads  >  POST Runkeeper Activity  >  (Un) Subscribe thread alerts  
Subject:POST Runkeeper Activity
Summary:How to post a runkeeper activity
Messages:3
Author:Gerben van Alphen
Date:2015-04-05 18:07:07
 

  1. POST Runkeeper Activity   Reply   Report abuse  
Picture of Gerben van Alphen Gerben van Alphen - 2015-04-05 18:07:07
Hi Guys,

I am just new over here.
I managed to GET data from Runkeeper, it really works great!

But now I am trying to Post an activity and don't seen any result or error.
Because I am an NewBee, a probably made a silly mistake...

$fields = '{"type": "Running", "equipment": "None", "start_time": "Sun, 5 Apr 2015 00:00:01", "notes": "My first late-night run", "path": [{"timestamp":0, "altitude":0, "longitude":-70.95182336425782, "latitude":42.312620297384676, "type":"start"}, {"timestamp":8, "altitude":0, "longitude":-70.95255292510987, "latitude":42.31230294498018, "type":"end"}], "post_to_facebook": true, "post_to_twitter": true}';

$success = $client->CallAPI(
'https://api.runkeeper.com/fitnessActivities/',
'POST', array($fields), array(
'FailOnAccessError'=>true,
'FollowRedirection'=>true
), $rkCreateActivity);

$success = $client->Finalize($success);
var_dump($client);



I also tried:
$fields = json_decode('{"type": "Running", "equipment": "None", "start_time": "Sun, 5 Apr 2015 00:00:01", "notes": "My first late-night run", "path": [{"timestamp":0, "altitude":0, "longitude":-70.95182336425782, "latitude":42.312620297384676, "type":"start"}, {"timestamp":8, "altitude":0, "longitude":-70.95255292510987, "latitude":42.31230294498018, "type":"end"}], "post_to_facebook": true, "post_to_twitter": true}');
$success = $client->CallAPI(
'https://api.runkeeper.com/fitnessActivities/',
'POST', $fields, array(
'FailOnAccessError'=>true,
'FollowRedirection'=>true
), $rkCreateActivity);

$success = $client->Finalize($success);
var_dump($client);



As result of the var_dump i got:
object(oauth_client_class)#1 (46) { ["error"]=> string(104) "it was not possible to access the API call: it was returned an unexpected response status 415 Response: " ["debug"]=> bool(false) ["debug_http"]=> bool(true) ["exit"]=> bool(false) ["debug_output"]=> string(0) "" ["debug_prefix"]=> string(14) "OAuth client: " ["server"]=> string(9) "RunKeeper" ["configuration_file"]=> string(24) "oauth_configuration.json" ["request_token_url"]=> string(0) "" ["dialog_url"]=> string(133) "https://runkeeper.com/apps/authorize?response_type=code&client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&state={STATE}&scope={SCOPE}" ["pin_dialog_url"]=> string(0) "" ["offline_dialog_url"]=> string(0) "" ["pin"]=> string(0) "" ["append_state_to_redirect_uri"]=> string(0) "" ["access_token_url"]=> string(32) "https://runkeeper.com/apps/token" ["oauth_version"]=> string(3) "2.0" ["url_parameters"]=> bool(false) ["authorization_header"]=> bool(true) ["token_request_method"]=> string(3) "GET" ["signature_method"]=> string(9) "HMAC-SHA1" ["redirect_uri"]=> string(48) "http://localhost/Swimmy/login_with_runkeeper.php" ["client_id"]=> string(32) "<client_id was here>" ["client_secret"]=> string(32) "<client secret was here>" ["api_key"]=> string(0) "" ["get_token_with_api_key"]=> bool(false) ["scope"]=> string(0) "" ["offline"]=> bool(false) ["access_token"]=> string(32) "<access token was here>" ["access_token_secret"]=> string(0) "" ["access_token_expiry"]=> string(0) "" ["access_token_type"]=> string(6) "Bearer" ["default_access_token_type"]=> string(0) "" ["access_token_parameter"]=> string(0) "" ["access_token_response"]=> NULL ["store_access_token_response"]=> bool(false) ["access_token_authentication"]=> string(0) "" ["refresh_token"]=> string(0) "" ["access_token_error"]=> string(104) "it was not possible to access the API call: it was returned an unexpected response status 415 Response: " ["authorization_error"]=> string(0) "" ["response_status"]=> int(415) ["oauth_username"]=> string(0) "" ["oauth_password"]=> string(0) "" ["grant_type"]=> string(18) "authorization_code" ["http_arguments"]=> array(0) { } ["oauth_user_agent"]=> string(70) "PHP-OAuth-API (http://www.phpclasses.org/oauth-api $Revision: 1.134 $)" ["response_time"]=> int(1428254483) }

I hope someone can help me :-) ?

  2. Re: POST Runkeeper Activity   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2015-04-05 20:44:42 - In reply to message 1 from Gerben van Alphen
According to the RunKeeper documentation you need to POST a request body in JSON encoded format but you also have to set a special request content type, so this is not the traditional POST request that sends parameters like in a Web form.

Using the documentation example, this works well:

$path_1 = new stdClass;
$path_1->timestamp = 0;
$path_1->altitude = 0;
$path_1->longitude = -70.95182336425782;
$path_1->latitude = 42.312620297384676;
$path_1->type = "start";

$path_2 = new stdClass;
$path_2->timestamp = 8;
$path_2->altitude = 0;
$path_2->longitude = -70.95255292510987;
$path_2->latitude = 42.31230294498018;
$path_2->type = "end";

$parameters = new stdClass;
$parameters->type = "Running";
$parameters->equipment = "None";
$parameters->start_time = "Sat, 1 Jan 2011 00:00:00";
$parameters->notes = "My first late-night run";
$parameters->path = array( $path_1, $path_2);
$parameters->post_to_facebook = false;
$parameters->post_to_twitter = false;

$success = $client->CallAPI(
'https://api.runkeeper.com/fitnessActivities',
'POST', array(), array(
'FailOnAccessError' => true,
'RequestBody' => json_encode($parameters),
'RequestContentType' => 'application/vnd.com.runkeeper.NewFitnessActivity+json'
), $activity);

  3. Re: POST Runkeeper Activity   Reply   Report abuse  
Picture of Gerben van Alphen Gerben van Alphen - 2015-04-05 21:01:01 - In reply to message 2 from Manuel Lemos
You are the BEST !!!!

Thank you!!