গুগল ডেটা প্রোটোকল ক্লায়েন্ট লাইব্রেরিতে ক্লায়েন্টলগইন

সতর্কতা : এই পৃষ্ঠাটি গুগলের পুরোনো এপিআই, গুগল ডেটা এপিআই সম্পর্কে; এটি শুধুমাত্র গুগল ডেটা এপিআই ডিরেক্টরিতে তালিকাভুক্ত এপিআইগুলির জন্য প্রাসঙ্গিক, যার মধ্যে অনেকগুলি নতুন এপিআই দিয়ে প্রতিস্থাপিত হয়েছে। একটি নির্দিষ্ট নতুন এপিআই সম্পর্কে তথ্যের জন্য, নতুন এপিআইয়ের ডকুমেন্টেশন দেখুন। একটি নতুন এপিআই দিয়ে অনুরোধ অনুমোদন সম্পর্কে তথ্যের জন্য, গুগল অ্যাকাউন্টস প্রমাণীকরণ এবং অনুমোদন দেখুন।

গুরুত্বপূর্ণ: নতুন অ্যাপ্লিকেশনের জন্য ClientLogin ব্যবহার করবেন না । পরিবর্তে, আরও নিরাপদ OAuth প্রমাণীকরণ প্রোটোকল ব্যবহার করুন। ClientLogin একটি অবচিত প্রমাণীকরণ প্রোটোকল এবং 20 এপ্রিল, 2015 থেকে এটি বন্ধ করা হচ্ছে। সেই সময়ে, ClientLogin অনুরোধগুলির আর উত্তর দেওয়া হবে না। যদি আপনার কাছে ClientLogin ব্যবহার করে এমন অ্যাপ্লিকেশন থাকে, তাহলে আমরা আপনাকে OAuth-এ স্থানান্তরিত করার জন্য উৎসাহিত করছি। পরবর্তী প্রধান রিলিজে এই লাইব্রেরিতে ClientLogin সমর্থন সরানো হবে।

এই ডকুমেন্টটি বর্ণনা করে যে প্রতিটি Google Data API ক্লায়েন্ট লাইব্রেরির মধ্যে ইনস্টল করা অ্যাপ্লিকেশনের জন্য Google এর প্রমাণীকরণ কীভাবে ব্যবহার করবেন।

ইনস্টল করা অ্যাপ্লিকেশনগুলি যাদের ব্যবহারকারীর ব্যক্তিগত ডেটা (একটি Google বা G Suite অ্যাকাউন্ট দ্বারা সুরক্ষিত) অ্যাক্সেসের প্রয়োজন হয়, তারা ব্যবহারকারীদের প্রমাণীকরণের জন্য প্রোগ্রাম্যাটিক উপায় হিসাবে ClientLogin ব্যবহার করতে পারে। একটি "ইনস্টল করা অ্যাপ্লিকেশন" হল এমন একটি অ্যাপ্লিকেশন যা একটি ডিভাইসে ইনস্টল করা থাকে, যেমন একটি ডেস্কটপ কম্পিউটার বা একটি সেল ফোন, একটি ওয়েব অ্যাপ্লিকেশনের বিপরীতে।

একটি ওয়েব অ্যাপ্লিকেশন তৈরি করছেন?

ওয়েব অ্যাপ্লিকেশনগুলির জন্য তাদের প্রমাণীকরণ পদ্ধতি হিসাবে ClientLogin ব্যবহার করা নিরুৎসাহিত করা হয়। পরিবর্তে, অনুগ্রহ করে Google Data API ক্লায়েন্ট লাইব্রেরিগুলির সাথে AuthSub ব্যবহার দেখুন।

পাঠকবর্গ

এই ডকুমেন্টটি এমন ডেভেলপারদের জন্য তৈরি যারা Google Data APIs ক্লায়েন্ট লাইব্রেরি ব্যবহার করে Google Data পরিষেবা অ্যাক্সেস করে এমন অ্যাপ্লিকেশন লিখতে চান। এই ডকুমেন্টটি ধরে নেয় যে আপনি ClientLogin ইন্টারফেসের সাথে পরিচিত। ClientLogin এর প্রোটোকলের সম্পূর্ণ বিবরণের জন্য, ইনস্টল করা অ্যাপ্লিকেশনগুলির জন্য প্রমাণীকরণ দেখুন।

Google Data API ক্লায়েন্ট লাইব্রেরিগুলি আপনার অ্যাপ্লিকেশনগুলিতে ClientLogin ব্যবহারে সহায়তা করার জন্য পদ্ধতি প্রদান করে। বিশেষ করে, একটি প্রমাণীকরণ টোকেন অর্জন, CAPTCHA চ্যালেঞ্জগুলি পরিচালনা, পরবর্তী ব্যবহারের জন্য প্রমাণীকরণ টোকেন প্রত্যাহার এবং প্রতিটি অনুরোধের সাথে সঠিক Authorization শিরোনাম পাঠানোর পদ্ধতি রয়েছে।

ক্লায়েন্ট লাইব্রেরি ছাড়াই ClientLogin এবং Google Data API ব্যবহার করা

ক্লায়েন্ট লাইব্রেরিগুলি কোনওভাবেই আপনার অ্যাপ্লিকেশনগুলিতে ClientLogin ব্যবহারের একমাত্র উপায় নয়। আপনার যা জানা দরকার তা ClientLogin ডকুমেন্টেশন, ইনস্টল করা অ্যাপ্লিকেশনগুলির জন্য প্রমাণীকরণে পাওয়া যাবে। তবে, ক্লায়েন্ট লাইব্রেরিগুলি আপনার Google ডেটা অ্যাপ্লিকেশনে ClientLogin ব্যবহারের জন্য সহায়ক পদ্ধতি সরবরাহ করে।

ClientLogin এবং Google Data API গুলির সাথে কাজ করা: ক্লায়েন্ট লাইব্রেরির উদাহরণ

এই বিভাগটি ClientLogin ডকুমেন্টেশনের " The ClientLogin Interface " বিভাগে বর্ণিত ধাপগুলি অনুসরণ করার জন্য Google Data APIs ক্লায়েন্ট লাইব্রেরি ব্যবহারের উদাহরণ দেয়।

এই ডকুমেন্টের উদাহরণগুলি গুগল ক্যালেন্ডারের সাথে ইন্টারঅ্যাক্ট করার পদ্ধতি প্রদর্শন করে (যদিও উদাহরণগুলি অনুসরণ করার জন্য আপনার ক্যালেন্ডার ডেটা API সম্পর্কে কিছু জানার প্রয়োজন নেই)।

একটি প্রমাণীকরণ টোকেন প্রাপ্ত করা

ClientLogin ব্যবহার করার জন্য, আপনার অ্যাপ্লিকেশনটি হ্যান্ডলার ClientLogin এর হ্যান্ডলার https://www.google.com/accounts/ClientLogin এ একটি HTTPS POST তৈরি করবে। POST বডিটি ডিফল্ট এনকোডিং application/x-www-form-urlencoded সহ একটি ফর্ম পোস্ট হিসাবে গঠন করা উচিত। ক্লায়েন্ট লাইব্রেরিগুলির একটি ব্যবহার করে, আপনি কোডের একটি একক লাইনে এই অনুরোধটি করতে পারেন।

নিম্নলিখিত নমুনাগুলি প্রথমে ক্যালেন্ডার ডেটা API-এর সাথে সংযোগকারী একটি পরিষেবা অবজেক্ট সেটআপ করে, এবং তারপর ClientLogin হ্যান্ডলারে একটি HTTP POST তৈরি করে।

জাভা

import com.google.gdata.client.*;
import com.google.gdata.client.calendar.*;

CalendarService client = new CalendarService("yourCompany-yourAppName-v1");
client.setUserCredentials("user@example.com", "pa$$word");

If you know your users will be using a G Suite account (as opposed to a Google/Gmail Account), you can streamline the login process by specifying the appropriate ClientLogin account type:

import com.google.gdata.client.*;
import com.google.gdata.client.calendar.*;

CalendarService client = new CalendarService("yourCompany-yourAppName-v1");
client.setUserCredentials("user@example.com", "pa$$word", ClientLoginAccountType.HOSTED);

.নেট

using Google.GData.Client;
using Google.GData.Calendar;

CalendarService client = new CalendarService("yourCompany-yourAppName-v1");
client.setUserCredentials("user@example.com", "pa$$word");
client.QueryAuthenticationToken(); // Authenticate the user immediately

If you know your users will be using a G Suite account (as opposed to a Google/Gmail Account), you can streamline the login process by specifying the appropriate ClientLogin account type:

using Google.GData.Client;
using Google.GData.Calendar;

GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("cl", "yourCompany-yourAppName-v1");
authFactory.AccountType = "HOSTED";

CalendarService client = new CalendarService(authFactory.ApplicationName);
client.RequestFactory = authFactory;
client.setUserCredentials("user@example.com", "pa$$word");
client.QueryAuthenticationToken(); // Authenticate the user immediately

পিএইচপি

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');

$serviceName = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name ('cl') for calendar
$applicationName = 'yourCompany-yourAppName-v1';

// Create an authenticated HTTP client
$httpClient = Zend_Gdata_ClientLogin::getHttpClient('user@example.com', 'pa$$word', $serviceName, null, $applicationName);
$client = new Zend_Gdata_Calendar($httpClient, $applicationName); // Create an instance of the Calendar service

If you know your users will be using a G Suite account (as opposed to a Google/Gmail Account), you can streamline the login process by specifying the appropriate ClientLogin account type:

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');

$serviceName = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$applicationName = 'yourCompany-yourAppName-v1';
$accountType = 'HOSTED';

$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
    'user@example.com', 'pa$$word', $serviceName, null, $applicationName, null, null, null, $accountType);
$client = new Zend_Gdata_Calendar($httpClient, $applicationName);

পাইথন

যদি আপনি GDClient এর উপর ভিত্তি করে নতুন v2.0+ ক্লাস ব্যবহার করেন, তাহলে ব্যবহার করুন:

import gdata.calendar.client

email = 'user@example.com'
password = 'pa$$word'
application_name = 'yourCompany-yourAppName-v1'

client = gdata.calendar.client.CalendarClient()
auth_token = client.ClientLogin(email, password,
                                application_name,
                                service='cl')

If you know your users will be using a G Suite account (as opposed to a Google/Gmail Account), you can streamline the login process by specifying the appropriate ClientLogin account type:

auth_token = client.ClientLogin(email, password,
                                application_name,
                                account_type='HOSTED',
                                service='cl')

Alternatively, if you're using the older v1.0 classes based off of GDataService, the calls are a bit different:

import gdata.calendar.service

email = 'user@example.com'
password = 'pa$$word'
application_name = 'yourCompany-yourAppName-v1'

client = gdata.calendar.service.CalendarService()
client.ClientLogin(email, password, source=application_name)

# OR, you can use ProgrammaticLogin()

client = gdata.calendar.service.CalendarService(email=email, password=password, source=application_name)
client.ProgrammaticLogin()

v2.0+ এর মতো, যদি আপনার ব্যবহারকারীরা G Suite অ্যাকাউন্ট ব্যবহার করেন তবে আপনি উপযুক্ত ClientLogin অ্যাকাউন্টের ধরণ নির্দিষ্ট করতে পারেন:

import gdata.calendar.service

client = gdata.calendar.service.CalendarService()
client.ClientLogin('user@example.com', 'pa$$word', account_type='HOSTED', source='yourCompany-yourAppName-v1')

See the request parameters section for a detailed explanation of each ClientLogin parameter. A complete list of available service names is available in the FAQ.

Note: By default, the client libraries set an account-type parameter to HOSTED_OR_GOOGLE. That means ClientLogin will first try to authenticate the user's credentials as a G Suite account. If that fails, it will try to authenticate as a Google Account. This becomes tricky if user@example.com is both a Google Account and a G Suite account. In that special case, set the account type to GOOGLE if the user wishes to use the Google Accounts version of user@example.com.

Once the login information has been successfully authenticated, Google returns a token, which your application will reference each time it requests access to the user's account, such as to GET or POST data. The token remains valid for a set length of time, defined by whichever Google service you're working with. Typically, tokens remain valid for 2 weeks.

Recalling an auth token

After your application has authenticated the user once, there's no need for them to input their credentials again. We recommend storing the Auth token in your database and recalling it as necessary. That will save the overhead of an additional HTTPS POST and a possible CAPTCHA challenge.

The libraries provide getters/setters for accessing the token:

Java

String token = '12345abcde'; // TODO: Read user's token from your database
client.setUserToken(token);

UserToken auth_token = (UserToken) client.getAuthTokenFactory().getAuthToken();
token = auth_token.getValue(); // token is '12345abcde'

.NET

String token = '12345abcde'; // TODO: Read user's token from your database
client.SetAuthenticationToken(token);

GDataGAuthRequestFactory requestFactory = (GDataGAuthRequestFactory) client.RequestFactory;
token = requestFactory.GAuthToken;  // token is '12345abcde'

PHP

$token = '12345abcde'; // TODO: Read user's token from your database
$client->getHttpClient()->setClientLoginToken($token);

$token = $client->getHttpClient()->getClientLoginToken(); // $token is '12345abcde'

Python

If you're using the newer v2.0+ classes based off of GDClient, use:

import gdata.gauth

token = '12345abcde'  # TODO: Read user's token from your database
client.auth_token = gdata.gauth.ClientLoginToken(token)

token = client.auth_token.token_string  # token is '12345abcde'

If you're using the older v1.0 classes based off of GDataService, the process is a bit different.

token = '12345abcde'  # TODO: Read user's token from your database
client.SetClientLoginToken(token)

token = client.GetClientLoginToken()  # token is '12345abcde'

Handling CAPTCHA challenges

A failure response from ClientLogin contains an error code and a URL to an error page that can be displayed to the user. If the error code is a CAPTCHA challenge, the response also includes a URL to a CAPTCHA image and a special token. Your application should be able to solicit an answer from the user and then retry the login request.

Java

String email = "user@example.com";
String password = "pa$$word";

try {
  client.setUserCredentials(email, password);
} catch (CaptchaRequiredException e) {
  System.out.println("Please visit " + e.getCaptchaUrl());
  System.out.print("Answer to the challenge? ");
  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  String answer = in.readLine();
  service.setUserCredentials(email, password, e.getCaptchaToken(), answer);

} catch (AuthenticationException e) {
  System.out.println(e.getMessage());
}

.নেট

try
{
  client.setUserCredentials("user@example.com", "pa$$word");
  client.QueryAuthenticationToken(); // Authenticate the user immediately
}
catch (CaptchaRequiredException e)
{
  Console.WriteLine("Please visit " + e.Url);
  Console.Write("Answer to the challenge? ");
  String answer = Console.ReadLine();
  GDataGAuthRequestFactory requestFactory = (GDataGAuthRequestFactory) client.RequestFactory;
  requestFactory.CaptchaAnswer = answer;
  requestFactory.CaptchaToken = e.Token;
  client.QueryAuthenticationToken(); // authenticate the user again
}
catch (InvalidCredentialsException e)
{
  Console.WriteLine(e.Message);
}
catch (AuthenticationException e)
{
  Console.WriteLine(e.Message);
}

PHP

$email = 'user@example.com';
$password = 'pa$$word';
$serviceName = 'cl';  // 'cl' is the service name for the Calendar API
$appName = 'yourCompany-yourAppName-v1';

try {
  $httpClient = Zend_Gdata_ClientLogin::getHttpClient($email, $password, $serviceName, null, $appName);
} catch (Zend_Gdata_App_CaptchaRequiredException $e) {
  echo '<a href="' . $e->getCaptchaUrl() . '">CAPTCHA answer required to login</a>';
  $answer = 'Your answer to the challenge';
  $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
      $email, $password, $serviceName, null, $appName, $e->getCaptchaToken(), $answer);

} catch (Zend_Gdata_App_AuthException $e) {
  echo 'Error: ' . $e->getMessage();
  if ($e->getResponse() != null) {
    echo 'Body: ' . $e->getResponse()->getBody();
  }
}

পাইথন

যদি আপনি GDClient এর উপর ভিত্তি করে নতুন v2.0+ ক্লাস ব্যবহার করেন, তাহলে ব্যবহার করুন:

import gdata.client

try:
  client.ClientLogin(email, password, application_name,
                     service='cl')
except gdata.client.CaptchaChallenge as challenge:
  print 'Please visit ' + challenge.captcha_url
  answer = raw_input('Answer to the challenge? ')
  client.ClientLogin(email, password, application_name,
                     captcha_token=challenge.captcha_token,
                     captcha_response=answer)
except gdata.client.BadAuthentication:
  exit('Users credentials were unrecognized')
except gdata.client.RequestError:
  exit('Login Error')

আপনি যদি GDataService এর উপর ভিত্তি করে পুরানো v1.0 ক্লাস ব্যবহার করেন, তাহলে প্রক্রিয়াটি একটু ভিন্ন।

import gdata.service

email = 'user@example.com'
password = 'pa$$word'
application_name = 'yourCompany-yourAppName-v1'

try:
  client.ClientLogin(email, password, source=application_name)
except gdata.service.CaptchaRequired:
  print 'Please visit ' + client.captcha_url
  answer = raw_input('Answer to the challenge? ')
  client.ClientLogin(email, password, source=application_name,
                     captcha_token=client.captcha_token,
                     captcha_response=answer)
except gdata.service.BadAuthentication:
  exit('Users credentials were unrecognized')
except gdata.service.Error:
  exit('Login Error')

ক্যাপচা সম্পর্কে আরও তথ্যের জন্য, "ইনস্টল করা অ্যাপ্লিকেশনের জন্য প্রমাণীকরণ" ডকুমেন্টেশনের ক্লায়েন্টলগইন প্রতিক্রিয়া বিভাগটি দেখুন।

অতিরিক্ত সম্পদ এবং নমুনা

উপরে ফিরে যান