「アカウントにログインしてください」と言って、何をしたいのか。ユーザーが自分のアカウントにアクセスするためのアクセス許可をアプリケーションに付与する場合、OAuth を使用できます。
Google には、多数の言語で記述された独自のライブラリがあります。Java、Python、および PHP を使用したいくつかの例は、https ://developers.google.com/google-apps/gmail/xoauth2_libraries で見つけることができます。
OAuth を使用する場合、Google に登録すると、ConsumerKey と ConsumerSecret が提供されます。これは、Google に対してアプリケーションを識別するものです。
ログインを許可するためのリンクを提供すると、ユーザーは Google ログインに移動し、ユーザーは自分のアカウントでログインし、許可を与えます。
GMail で OAuth を使用する際に問題がありましたが、連絡先などで問題なく管理できました。たとえば、これはすべてのユーザーの連絡先を取得するために使用しているコードです
public List<Person> GetContacts()
{
OAuthParameters parameters = null;
GOAuthRequestFactory requestFactory = null;
ContactsService service = null;
ContactsQuery feedQuery = null;
ContactsFeed feed = null;
List<Person> contacts = null;
try
{
if (ConsumerKey == String.Empty) throw new ValueIsEmptyOrNullException("ConsumerKey");
if (ConsumerSecret == String.Empty) throw new ValueIsEmptyOrNullException("ConsumerSecret");
if (OAuthCallback == String.Empty) throw new ValueIsEmptyOrNullException("OAuthCallback");
if (SignatureMethod == String.Empty) throw new ValueIsEmptyOrNullException("SignatureMethod");
if (ApplicationName == String.Empty) throw new ValueIsEmptyOrNullException("ApplicationName");
if (Token == String.Empty) throw new ValueIsEmptyOrNullException("Token");
if (Nonce == String.Empty) throw new ValueIsEmptyOrNullException("Nonce");
if (Verifier == String.Empty) throw new ValueIsEmptyOrNullException("Verifier");
if (Scope == String.Empty)
Scope = "https://www.google.com/m8/feeds";
parameters = new OAuthParameters();
parameters.ConsumerKey = ConsumerKey;
parameters.ConsumerSecret = ConsumerSecret;
parameters.Scope = Scope;
parameters.Callback = OAuthCallback;
parameters.SignatureMethod = SignatureMethod;
parameters.Timestamp = Toolbox.GenerateTimeStamp();
parameters.Token = Token;
parameters.TokenSecret = TokenSecret;
parameters.Nonce = Nonce;
parameters.Verifier = Verifier;
requestFactory = new GOAuthRequestFactory("c1", ApplicationName, parameters);
service = new ContactsService(ApplicationName);
service.RequestFactory = requestFactory;
feedQuery = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));
feed = service.Query(feedQuery);
if (feed.Entries.Count > 0)
{
contacts = new List<Person>();
foreach (ContactEntry contact in feed.Entries)
{
try
{
if (contact.Name != null)
{
Person person = new Person();
int idStart = contact.Id.Uri.ToString().LastIndexOf('/');
if (idStart > 0)
{
person.PersonId = contact.Id.Uri.ToString().Substring(contact.Id.Uri.ToString().LastIndexOf('/') + 1);
}
else
{
person.PersonId = contact.Id.Uri.ToString();
}
person.GivenName = contact.Name.GivenName;
person.Surname = contact.Name.FamilyName;
person.Birthday = contact.Birthday;
person.Initials = contact.Initials;
person.Location = contact.Location;
person.MaidenName = contact.MaidenName;
person.Occupation = contact.Occupation;
person.Photograph = contact.PhotoUri.ToString();
person.Surname = contact.Name.FamilyName;
if (contact.Emails.Count > 0)
person.Email = contact.Emails[0].Address;
contacts.Add(person);
}
}
catch (System.Exception ex)
{
throw ex;
}
finally
{
}
}
}
}
catch (Exception ex)
{
throw ex;
}
return contacts;
}