(평판 때문에 http가 삭제됨) Google의 "GoogleApisSamples"프로젝트로 Google Site Verification API을 테스트 중이지만 리디렉션 URI와 관련된 문제가 있습니다. 내 GoogleDrive 응용 프로그램에서 client_secrets.json (리디렉션 uri가 설정된 상태로)이 프로그램이 가져 오는 리디렉션 URI는 "localhost : 1168/authorize /"(변경)와 유사합니다. 리디렉션 URI를 'www.google.com'및 'www.google.com/'으로 설정했습니다.Google 사이트 확인 API .NET 리디렉션 URI가 채택되지 않았습니다
namespace SiteVerification.VerifySite
{
internal class Program
{
[STAThread]
static void Main(string[] args)
{
// Display the header and initialize the sample.
Console.WriteLine("Site Verification sample");
Console.WriteLine("========================");
UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { SiteVerificationService.Scope.Siteverification },
"user", CancellationToken.None, new FileDataStore("SiteVerification.VerifySite")).Result;
}
// Create the service.
var service = new SiteVerificationService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "SiteVerification API Sample",
});
RunVerification(service);
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
/// <summary>
/// This method contains the actual sample code.
/// </summary>
private static void RunVerification(SiteVerificationService service)
{
// Request user input.
Console.WriteLine("Please enter the URL of the site to verify:");
var site = Console.ReadLine();
Console.WriteLine();
// Example of a GetToken call.
Console.WriteLine("Retrieving a meta token ...");
var request = service.WebResource.GetToken(new SiteVerificationWebResourceGettokenRequest()
{
VerificationMethod = "meta",
Site = new SiteVerificationWebResourceGettokenRequest.SiteData()
{
Identifier = site,
Type = "site"
}
});
var response = request.Execute();
Console.WriteLine("Token: " + response.Token);
Console.WriteLine();
Console.WriteLine("Please place this token on your webpage now.");
Console.WriteLine("Press ENTER to continue");
Console.ReadLine();
Console.WriteLine();
// Example of an Insert call.
Console.WriteLine("Verifying...");
var body = new SiteVerificationWebResourceResource();
body.Site = new SiteVerificationWebResourceResource.SiteData();
body.Site.Identifier = site;
body.Site.Type = "site";
var verificationResponse = service.WebResource.Insert(body, "meta").Execute();
Console.WriteLine("Verification:" + verificationResponse.Id);
Console.WriteLine("Verification successful!");
}
}
}
그리고 내 "client_secrets.json는"
{
"web": {
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"client_secret": "CLIENT_SECRET",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"client_email": "STUFF",
"redirect_uris": [
"http://www.google.com/",
"http://www.google.com"
],
"client_x509_cert_url": "STUFF",
"client_id": "CLIENT_ID",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"javascript_origins": [
"https://www.google.com"
]
}
}
And the error I get is:
(I는 대문자로 물건을 변경)
- 오류입니다.
오류 :
응용 프로그램을 redirect_uri_mismatch : GoogleApisSamples
요청의 리디렉션 URI : 로컬 호스트 : 1168/인증/a를 URI를 재 등록 일치하지 않습니다.
이 코드는 사이트 서비스 API 용입니다. 왜 Google 드라이브 API에 태그를 추가 했습니까? – DaImTo
Sry이 주제를 처음 사용합니다. 그리고 SiteServiceAPI에 대한 태그를 찾을 수 없습니다. (내 담당자 때문에 카메라를 만들 수 없습니다) – carlilord
개발자 콘솔의 응용 프로그램에서 얻은 client_secrets.json으로 client_secrets.json을 대체 했습니까? 샘플 코드? – DaImTo