我正在使用Google的Place API来自动填充用户输入的城市名称(网页).加载API时将语言(pt-BR)作为参数传递,文本框正在以葡萄牙语正确填充,但是当执行方法getPlace()时,它将以英语返回结果(country和administrative_area_level_1).
我不确定问题是Google API,它们是葡萄牙语的翻译还是我错过的.我试图加载它通过西班牙语(es),英语(en)和意大利语(它)作为语言的参数并按预期工作.
这是我加载的方式:
<script src="https://maps.googleapis.com/maps/api/js?key=[myapikey]&signed_in=true&libraries=places&callback=initAutocomplete&language=pt-BR" async defer></script>
Run Code Online (Sandbox Code Playgroud)
...以及我如何根据Google的示例代码获得结果:
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();
Run Code Online (Sandbox Code Playgroud)
我也使用反向地理编码API传递place_id,问题是相同的(C#代码).
var apikey = "[myserverapikey]";
var requestUri = string.Format("https://maps.googleapis.com/maps/api/geocode/json?place_id={0}&key={1}", place_id, apikey);
var idiomas = new string[] {"pt-BR", "es", "en-us", "it"};
string responseContent = string.Empty;
foreach (var idioma in idiomas)
{
HttpWebRequest request = WebRequest.Create(requestUri) as HttpWebRequest;
request.Headers.Add(HttpRequestHeader.AcceptLanguage, idioma);
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
StreamReader reader = new StreamReader(response.GetResponseStream());
var jsontext = reader.ReadToEnd().Trim();
responseContent += jsontext;
var …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Owin在Google.Apis请求中提供的AccessToken,但我收到异常System.InvalidOperationException(附加信息:访问令牌已过期但我们无法刷新它).
我的Google身份验证配置正常,我可以使用它成功登录我的应用程序.我将context.AccessToken存储为身份验证回调中的声明(GoogleOAuth2AuthenticationProvider的OnAuthenticated"event").
我的Startup.Auth.cs配置(app.UseGoogleAuthentication(ConfigureGooglePlus()))
private GoogleOAuth2AuthenticationOptions ConfigureGooglePlus()
{
var goolePlusOptions = new GoogleOAuth2AuthenticationOptions()
{
ClientId = "Xxxxxxx.apps.googleusercontent.com",
ClientSecret = "YYYYYYzzzzzz",
Provider = new GoogleOAuth2AuthenticationProvider()
{
OnAuthenticated = context =>
{
context.Identity.AddClaim(new System.Security.Claims.Claim("Google_AccessToken", context.AccessToken));
return Task.FromResult(0);
}
},
SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie
};
goolePlusOptions.Scope.Add("https://www.googleapis.com/auth/plus.login");
goolePlusOptions.Scope.Add("https://www.googleapis.com/auth/userinfo.email");
return goolePlusOptions;
Run Code Online (Sandbox Code Playgroud)
}
抛出异常的代码(Execute()方法)
var externalIdentity = await AuthenticationManager.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie);
var accessTokenClaim = externalIdentity.FindAll(loginProvider + "_AccessToken").First();
var secrets = new ClientSecrets()
{
ClientId = "Xxxxxxx.apps.googleusercontent.com",
ClientSecret = "YYYYYYzzzzzz"
};
IAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = …Run Code Online (Sandbox Code Playgroud) asp.net-mvc google-oauth google-api-dotnet-client owin google-plus-signin
我将我的ASP.NET MVC Web应用程序从成员身份转移到身份验证,因为我无法再在LinkedIn上进行身份验证.
Facebook身份验证仍然正常,但LinkedIn总是在GetExternalLoginInfo调用后返回null loginInfo.
对于LinkedIn我正在使用Owin LinkedIn提供程序:用于.NET的LinkedIn API.我也试图跟随杰里·佩尔泽的这篇文章不成功.
Application调用执行ExecuteResult方法的ExternalLogin Action并回调ExternalLoginCallback(在我允许访问应用程序之后).如前所述,方法AuthenticationManager.GetExternalLoginInfoAsync()始终返回null loginInfo.
我检查了LinkedIn中的应用程序设置,一切似乎都没问题.
行动!我差点忘了说LinkedIn正在返回带有一般错误消息的URL:"GET/Account/ExternalLoginCallback?error = access_denied HTTP/1.1"
我可以使用DotNetOpenAuth.Clients(托管的github)进行身份验证,但我想使用Identity.
Startup.Auth.cs
var linkedInOptions = new LinkedInAuthenticationOptions();
linkedInOptions.ClientId = "Xxxxx";
linkedInOptions.ClientSecret = "Yyyyyyy";
linkedInOptions.Scope.Add("r_fullprofile");
linkedInOptions.Provider = new LinkedInAuthenticationProvider()
{
OnAuthenticated = async context =>
{
context.Identity.AddClaim(new System.Security.Claims.Claim("LinkedIn_AccessToken", context.AccessToken));
}
};
linkedInOptions.SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie;
app.UseLinkedInAuthentication(linkedInOptions);
Run Code Online (Sandbox Code Playgroud)
ExternalLogin
public ActionResult ExternalLogin(string provider, string returnUrl)
{
// Request a redirect to the external login provider
return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl …Run Code Online (Sandbox Code Playgroud) authentication asp.net-mvc linkedin oauth-2.0 asp.net-identity