【发布时间】:2020-07-27 09:08:15
【问题描述】:
if ( is_null( $this->github_response ) ) { // Do we have a response?
$request_uri = sprintf( 'https://api.github.com/repos/%s/%s/releases', $this->username, $this->repository ); // Build URI
if( $this->authorize_token ) { // Is there an access token?
/* $request_uri = add_query_arg( 'access_token', $this->authorize_token, $request_uri ); // Append it*/
$basicauth = 'token ' . $this->authorize_token;
$headers = array(
'Authorization' => $basicauth
);
}
$pload = array(
'headers' => $headers
);
$response = json_decode( wp_remote_retrieve_body( wp_remote_get( $request_uri, $pload ) ), true ); // Get JSON and parse it
if( is_array( $response ) ) { // If it is an array
$response = current( $response ); // Get the first item
}
if( $this->authorize_token ) { // Is there an access token?
$response['zipball_url'] = add_query_arg( 'access_token', $this->authorize_token, $response['zipball_url'] ); // Update our zip url with token
}
$this->github_response = $response; // Set it to our property
}
我的目标是从最新的 git 版本中获取可下载的 url。我还使用此代码获得了可下载的 url。但问题是 github 向我发送一封关于已弃用问题的电子邮件:Deprecating API authentication through query parameters。
我阅读了 github 的文档,但无法解决。谁能帮帮我?
【问题讨论】:
-
也对此感兴趣。
-
您是否能够弄清楚如何更新代码并在标头中发送令牌?
-
是的,我能够解决问题