나는 goodreads (http://www.goodreads.com) 용 windows 8 앱을 개발 중입니다. http://code.msdn.microsoft.com/windowsapps/Web-Authentication-d0485122/view/Discussions에있는 웹 인증 브로커 샘플을 따르고 있습니다. 나는 oauth 토큰과 oauth 토큰을 성공적으로 얻을 수 있었다.Windows 8 앱의 Goodreads에서 Access Token 받기
하지만 다시 보내고 goodreads에서 액세스 토큰을 얻을 수 없습니다. 아래 코드에서 언급 한 바와 같이 획득 된 oauth 토큰과 토큰 sectret을 사용하여 생성 된 URL을 보내려고합니다. oauth 토큰을 사용하여 액세스하려고합니다. OAuth를 사용하여 Goodreads API로부터 받았습니다.
주어진 코드에서 "GetResponse2"변수는 항상 비동기 데이터 전송 메소드에서 null로 설정됩니다. 나는 그것이 URL의 구성 때문에 생긴 것 같지만 URL에서 어디서 잘못되었는지 알 수 없다. 누군가 나를 도울 수 있기를 바랍니다.
if (oauth_token != null)
{
GoodreadsUrl = "https://www.goodreads.com/oauth/authorize?oauth_token=" + oauth_token;
System.Uri StartUri = new Uri(GoodreadsUrl);
System.Uri EndUri = new Uri(GoodreadsCallbackUrl);
WebAuthenticationResult WebAuthenticationResult =
await WebAuthenticationBroker.AuthenticateAsync(
WebAuthenticationOptions.None,
StartUri,EndUri);
var response = WebAuthenticationResult.ResponseData;
if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
{
TimeSpan SinceEpoch2 = DateTime.UtcNow - new DateTime(1970, 1, 1);
Random Rand2 = new Random();
GoodreadsUrl = "http://www.goodreads.com/oauth/access_token";
Int32 Nonce2 = Rand2.Next(1000000000);
//
// Compute base signature string and sign it.
// This is a common operation that is required for all requests even after the token is obtained.
// Parameters need to be sorted in alphabetical order
// Keys and values should be URL Encoded.
//
String SigBaseStringParams2 = "oauth_callback=" + Uri.EscapeDataString(GoodreadsCallbackUrl);
SigBaseStringParams2 += "&" + "oauth_consumer_key=" + GoodreadsClientId;
SigBaseStringParams2 += "&" + "oauth_token=" + oauth_token;
SigBaseStringParams2 += "&" + "oauth_verifier=" + oauth_token_secret;
SigBaseStringParams2 += "&" + "oauth_nonce=" + Nonce2.ToString();
SigBaseStringParams2 += "&" + "oauth_signature_method=HMAC-SHA1";
SigBaseStringParams2 += "&" + "oauth_timestamp=" + Math.Round(SinceEpoch2.TotalSeconds);
SigBaseStringParams2 += "&" + "oauth_version=1.0";
String SigBaseString2 = "GET&";
SigBaseString2 += Uri.EscapeDataString(GoodreadsUrl) + "&" + Uri.EscapeDataString(SigBaseStringParams2);
IBuffer KeyMaterial2 = CryptographicBuffer.ConvertStringToBinary(GoodreadsClientSecret + "&", BinaryStringEncoding.Utf8);
MacAlgorithmProvider HmacSha1Provider2 = MacAlgorithmProvider.OpenAlgorithm("HMAC_SHA1");
CryptographicKey MacKey2 = HmacSha1Provider2.CreateKey(KeyMaterial2);
IBuffer DataToBeSigned2 = CryptographicBuffer.ConvertStringToBinary(SigBaseString2, BinaryStringEncoding.Utf8);
IBuffer SignatureBuffer2 = CryptographicEngine.Sign(MacKey2, DataToBeSigned2);
String Signature2 = CryptographicBuffer.EncodeToBase64String(SignatureBuffer2);
String DataToPost2 = "OAuth oauth_callback=\"" + Uri.EscapeDataString(GoodreadsCallbackUrl) + "\", oauth_consumer_key=\"" + GoodreadsClientId + "\", oauth_nonce=\"" + Nonce2.ToString() + "\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"" + Math.Round(SinceEpoch2.TotalSeconds) + "\", oauth_version=\"1.0\", oauth_signature=\"" + Uri.EscapeDataString(Signature2) + "\"";
GoodreadsUrl += "?" + SigBaseStringParams2 + "&oauth_signature=" + Uri.EscapeDataString(Signature2);
String GetResponse2 = await SendDataAsync(GoodreadsUrl);
// DebugPrint("Received Data: " + GetResponse);
}
제발 당신을 위해 문제를 해결하도록 요청하지 마십시오. 문제를 직접 해결하려고 시도한 후 왜 결과가 정확한지를 보여주고 작동하지 않는 이유를 설명해주십시오. 당신이 꼭 알아야 할 훌륭한 기사는 "[당신은 무엇을 했습니까?] (http://whathaveyoutried.com/)"를보십시오. –
감사합니다. 존, 곧 질문을 업데이트하겠습니다. – har