How to get Authentication code from google plus when login in c#
how to get Authentication Code from google plus when login in c#,I use
this code below but it error and It gets authentication code is null
protected PlusService plusService;
protected Person me;
private IAuthorizationState _authstate;
public MainWindow()
{
InitializeComponent();
me = null;
_authstate = null;
}
public static class ClientCredentials
{
static public string ClientID = "521993821366.apps.googleusercontent.com";
static public string ClientSecret = "zeBqO2pghQAWeef_wUV6b365";
}
private OAuth2Authenticator<NativeApplicationClient> CreateAuthenticator()
{
var provider = new
NativeApplicationClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier = ClientCredentials.ClientID;
provider.ClientSecret = ClientCredentials.ClientSecret;
var authenticator =new
OAuth2Authenticator<NativeApplicationClient>(provider,GetAuthorization1);
return authenticator;
}
private static IAuthorizationState
GetAuthorization1(NativeApplicationClient arg)
{
// Get the auth URL:
IAuthorizationState state = new AuthorizationState(new[] {
PlusService.Scopes.PlusLogin.GetStringValue()});
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri = arg.RequestUserAuthorization(state);
// Request authorization from the user (by opening a browser window):
Process.Start(authUri.ToString());
Console.Write(" Authorization Code: ");
string authCode = Console.ReadLine();
Console.WriteLine();
var result = arg.ProcessUserAuthorization(authCode, state);
return result;
}
//Function to get Friend List and ProfileInfo public void Authenticate() {
var auth = CreateAuthenticator(); plusService = new PlusService(new
BaseClientService.Initializer() { Authenticator = auth }); if (plusService
!= null) { PeopleResource.GetRequest getReq =
plusService.People.Get("me"); PeopleResource.ListRequest listRequest =
plusService.People.List("me", PeopleResource.CollectionEnum.Visible);
PeopleFeed friendFeed = listRequest.Fetch(); Person me = getReq.Fetch();
if (me != null)
{
statusText.Text = "You successfully Authenticated!";
resultText.Text = "UserName: " + me.DisplayName + "\nURL: " +
me.Url +
"\nProfile id: " + me.Id + "\nLocation:" + me.Gender +
me.Emails;
}
Dictionary<string, string> dd = new Dictionary<string, string>();
foreach (Person friend in friendFeed.Items)
{
dd.Add(friend.DisplayName, friend.Id);
}
}
}
No comments:
Post a Comment