0

我正在使用这个作曲家包https://github.com/basvandorst/StravaPHP

OAUTH 工作正常,它为我生成带有访问令牌和用户 ID 等的 JSON。

但是每当我尝试使用其他功能时,它都会返回 404 not found。

输出是这样的:

{"token_type":"Bearer","access_token":"077058e0c800881c72a4b10a04a520d5898d4e3e","athlete":{"id":35670467,"username":"amir_do","resource_state":2,"firstname":"Amir","lastname":"Do","city":null,"state":null,"country":null,"sex":"M","premium":false,"summit":false,"created_at":"2018-10-13T13:55:41Z","updated_at":"2018-10-13T13:56:25Z","badge_type_id":0,"profile_medium":"https://lh5.googleusercontent.com/-ku6v9lKNgYY/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbASj8KhClhwnVYVqRrEG2oiYzWPbA/mo/photo.jpg","profile":"https://lh5.googleusercontent.com/-ku6v9lKNgYY/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbASj8KhClhwnVYVqRrEG2oiYzWPbA/mo/photo.jpg","friend":null,"follower":null,"email":"goncalomaia97@gmail.com"}}
35670467


Client error: `GET https://www.strava.com/api/athletes/35670467/stats?access_token=077058e0c800881c72a4b10a04a520d5898d4e3e` resulted in a `404 Not Found` response: {"message":"Record Not Found","errors":[{"resource":"resource","field":"path","code":"invalid"}]}

这是我当前的 callback.php 页面代码:

<?php 
include 'vendor/autoload.php';
use Strava\API\Client;
use Strava\API\Exception;
use Strava\API\Service\REST;
session_start();
$client = new GuzzleHttp\Client();
global $connect;

require_once("configs/database.php");
$connect = new mysqli($config['database']['host'],$config['database']['user'],$config['database']['pass'],$config['database']['db']); 

$code = $_GET['code'];
$state = $_GET['state'];
$scope = $_GET['scope'];

$user = $_SESSION['username'];
$check = $connect->query("SELECT * FROM users WHERE email = '$user'");
$fetch = $check->fetch_array(MYSQLI_ASSOC);

$apix = $fetch['api'];
$api_secretx = $fetch['api_secret'];

$client = new GuzzleHttp\Client();
$data   = [
    "client_id"    => $apix,
    "client_secret" => $api_secretx,
    "code" => $code
];

$result = $client->post('https://www.strava.com/oauth/token', ['json' => $data]);


print "<pre>";
print_r( $result->getBody()->getContents() );
print "</pre>";


$bodyb = $result->getBody();
$varx = json_decode((string) $bodyb, true);

$token = $varx['access_token'];
$id = $varx['athlete']['id'];


$_SESSION['token'] = $token;

printf($id);
try {
// REST adapter (We use `Guzzle` in this project)
$adapter = new \GuzzleHttp\Client(['base_uri' => 'https://www.strava.com/api/v3']);
// Service to use (Service\Stub is also available for test purposes)
$service = new \Strava\API\Service\REST($token, $adapter);

// Receive the athlete!
$client = new Client($service);
$athlete = $client->getAthleteStats($id);
print_r($athlete);

} catch(Exception $e) {
    print $e->getMessage();
}
4

1 回答 1

1
$adapter = new \GuzzleHttp\Client(['base_uri' => 'https://www.strava.com/api/v3']);

将其更改为此(它应该是尾随):

$adapter = new \GuzzleHttp\Client(['base_uri' => 'https://www.strava.com/api/v3/']);
于 2018-10-21T12:34:10.433 回答