Recommend this page to a friend! |
PHP OAuth Library | > | PHP OAuth Library package blog | > | Learn with a PHP OAut... | > | All threads | > | connect garmin oauth | > | (Un) Subscribe thread alerts |
|
![]() Hello, I have a problem connecting garmin oauth, it does not show me any activity performed by the user could help me locate my mistake and how to fix it thanks.
/* <?php session_start(); require 'config.php'; if(!isset($_GET['oauth_token'])) { try { $oauth = new OAuth(API_KEY_GARMIN,API_SEC_GARMIN); $oauth->enableDebug(); $request_token_info = $oauth->getRequestToken(REQ_URL_GARMIN); if(!empty($request_token_info)) { $_SESSION['ses_request_token']=$request_token_info;; $_SESSION['ses_oauth_token']=$request_token_info['oauth_token']; $_SESSION['ses_oauth_token_secret']=$request_token_info['oauth_token_secret']; header('Location: ' .AUTH_URL_GARMIN.'?oauth_token='.$request_token_info['oauth_token'] ); } else { print "Fallo obteniendo el request_token, la respuesta fue: " . $oauth->getLastResponse(); session_destroy(); } } catch(OAuthException $E) { echo "Response: ". $E->lastResponse . "\n"; } } // 3. if its a callback url if(isset($_GET['oauth_token'])){ try { $oauth = new OAuth(API_KEY_GARMIN,API_SEC_GARMIN); $oauth->setToken( $_GET['oauth_token'] ,$_SESSION['ses_oauth_token_secret']); $access_token_info = $oauth->getAccessToken(ACC_URL_GARMIN); $response_info = $oauth->getLastResponseInfo(); if(!empty($access_token_info)) { $_SESSION['oauth_verifier'] = $_GET['oauth_verifier']; $_SESSION['ses_oauth_token'] = $access_token_info['oauth_token']; $_SESSION['ses_oauth_token_secret'] = $access_token_info['oauth_token_secret']; } else { print "Falló obteniendo el token de acceso, la respuesta fue: " . $oauth->getLastResponse(); session_destroy(); } $oauth = new OAuth(API_KEY_GARMIN,API_SEC_GARMIN); $oauth->setToken($access_token_info['oauth_token'],$access_token_info['oauth_token_secret']); $oauth->setAuthType(OAUTH_AUTH_TYPE_FORM); $json = json_decode($oauth->getLastResponse()); var_dump($json); } catch(OAuthException $E) { echo "Respuesta: ". $E->lastResponse . "\n"; session_destroy(); } } ?> */
![]() That code uses some other class.
Try this class using the login_with_garmin.php example script. phpclasses.org/package/7700-PHP-Aut ...
![]() Hi I'm now using your code but I still return the following error ->
OAuth client Error Error: it was not possible to access the API call: it was returned an unexpected response 301 Response status: <?php require('http.php'); require('oauth_client.php'); $client = new oauth_client_class; $client->debug = true; $client->debug_http = true; $client->server = 'Garmin2Legged'; $client->redirect_uri = 'https://testing.colectigo.com/fitness-apis/garmin/'; $client->client_id = '689c52cc-24f7-4ee6-81f2-1fab65796ed3'; $client->client_secret = 'wht05JKNRSeVcfZRGlvNutUhIihg1YslR0g'; $application_line = __LINE__; if(strlen($client->client_id) == 0 || strlen($client->client_secret) == 0) die('Please go to Garmin Apps page , '.'create an application, and in the line '.$application_line.' set the client_id to Consumer key and client_secret with Consumer secret. '); if(($success = $client->Initialize())) { if(($success = $client->Process())) { if(strlen($client->access_token)) { $activitySummaryRequest = new stdClass; $activitySummaryRequest->consumerToken = $client->client_id; $activitySummaryRequest->unacknowledgedOnly=false; $activitySummaryRequest->beginTimeMillis=0; $activitySummaryRequest->endTimeMillis = time()*1000; $activitySummary = new stdClass; $activitySummary->activitySummaryRequest = $activitySummaryRequest; $activityRequest = new stdClass; $activityRequest->GET_ACTIVITY_SUMMARY = array( $activitySummary ); $WELLNESS = new stdClass; $WELLNESS->activityRequests = array( $activityRequest ); $serviceRequests = new stdClass; $serviceRequests->WELLNESS = $WELLNESS; $parameters = new stdClass; $parameters->serviceRequests = $serviceRequests; $success = $client->CallAPI('http://gcsapitest.garmin.com/gcs-api/api/json','POST', array(), array('FailOnAccessError' => true, 'RequestBody' => json_encode($parameters), 'RequestContentType' => 'application/octet-stream', ), $activity); } } $success = $client->Finalize($success); } if($client->exit) exit; if($success) { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Garmin OAuth client results</title> </head> <body> <?php echo '<h1>CONECTADO CON EXITO GARMIN!</h1>'; echo '<pre>Activity:', "\n\n", HtmlSpecialChars(print_r($activity, 1)), '</pre>'; ?> </body> </html> <?php } else { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>OAuth client error</title> </head> <body> <h1>OAuth client error</h1> <?php session_destroy();?> <pre>Error: <?php echo HtmlSpecialChars($client->error); ?></pre> </body> </html> <?php } ?>
![]() I tried it here with your credentials and it failed with error 400. Then I tried with my own credentials and it worked. This suggests that your credentials may not be valid.
Keep in mind that if you publish your credentials anywhere, Garmin may invalidate them. I would check with them what is going on. |
info at phpclasses dot org
.