গুরুত্বপূর্ণ : 1 মে, 2024 থেকে, Apple-এর জন্য GoogleSignIn-iOS সহ সাধারণভাবে ব্যবহৃত SDK ব্যবহার করে এমন iOS অ্যাপ্লিকেশনগুলির জন্য গোপনীয়তা প্রকাশ এবং স্বাক্ষর প্রয়োজন ৷ 1 মে, 2024 এর আগে GoogleSignIn-iOS v7.1.0+ এ আপগ্রেড করুন ৷ আমাদের আপগ্রেড নির্দেশিকা অনুসরণ করুন৷
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
কিছু Google পরিষেবা, যেমন ড্রাইভ, Gmail এবং আরও অনেকগুলি, সর্বজনীন API প্রদান করে যা আপনি অ্যাপ তৈরি করতে ব্যবহার করতে পারেন যা ব্যবহারকারীদের এই পরিষেবাগুলিতে তাদের ডেটা নিয়ে কাজ করতে সহায়তা করে৷ এই পরিষেবাগুলি অ্যাক্সেস করার জন্য, অ্যাপগুলিকে অবশ্যই OAuth 2.0 ক্লায়েন্ট ফ্লোগুলির একটি প্রয়োগ করতে হবে যাতে ব্যবহারকারীদের কাছ থেকে সম্মতি পেতে এবং অ্যাক্সেস টোকেনগুলি পেতে হয়, যা APIগুলিতে অ্যাক্সেস দেয়৷
আপনি Google সাইন-ইন লাইব্রেরি ব্যবহার করতে পারেন, যা আপনার জন্য OAuth 2.0 ফ্লো প্রয়োগ করে, সাইন-ইন করা ব্যবহারকারীর জন্য অ্যাক্সেস টোকেন পেতে।
আপনি একটি Google API-এ কল করার আগে, GIDGoogleUser এর grantedScopes বৈশিষ্ট্য ব্যবহার করে আপনার অ্যাপে কোন স্কোপ ইতিমধ্যেই মঞ্জুর করা হয়েছে তা পরীক্ষা করে দেখুন:
NSString*driveScope=@"https://www.googleapis.com/auth/drive.readonly";// Check if the user has granted the Drive scopeif(![user.grantedScopescontainsObject:driveScope]){// request additional drive scope}
ব্যবহারকারীর দ্বারা একটি নির্দিষ্ট সুযোগ দেওয়া হয়েছে কিনা তার উপর ভিত্তি করে, একটি নির্দিষ্ট মিথস্ক্রিয়াকে সমর্থন করার জন্য আপনাকে একটি অতিরিক্ত সুযোগের জন্য অনুরোধ করতে হতে পারে।
2. অতিরিক্ত সুযোগের জন্য অনুরোধ করুন
আপনি যদি অতিরিক্ত সুযোগের জন্য অনুরোধ করতে চান, তাহলে ব্যবহারকারীকে আপনার অ্যাপকে অতিরিক্ত অ্যাক্সেস দিতে বলার জন্য addScopes:presentingViewController:completion বা addScopes:presentingWindow:completion কল করুন।
letadditionalScopes=["https://www.googleapis.com/auth/drive.readonly"]guardletcurrentUser=GIDSignIn.sharedInstance.currentUserelse{return;/* Not signed in. */}currentUser.addScopes(additionalScopes,presenting:self){signInResult,erroringuarderror==nilelse{return}guardletsignInResult=signInResultelse{return}// Check if the user granted access to the scopes you requested.}
উদ্দেশ্য-C
NSArray*additionalScopes=@[@"https://www.googleapis.com/auth/drive.readonly"];GIDGoogleUser*currentUser=GIDSignIn.sharedInstance.currentUser;[currentUseraddScopes:additionalScopespresentingViewController:selfcompletion:^(GIDSignInResult*_NullablesignInResult,NSError*_Nullableerror){if(error){return;}if(signInResult==nil){return;}// Check if the user granted access to the scopes you requested.}];
3. নতুন টোকেন সহ একটি API কল করুন৷
আপনার Google API কলগুলিতে সর্বদা অপ্রয়োজনীয় অ্যাক্সেস টোকেন সংযুক্ত থাকে তা নিশ্চিত করতে, কলগুলিকে একটি refreshTokensIfNeededWithCompletion: ব্লকে মুড়ে দিন:
সুইফট
currentUser.refreshTokensIfNeeded{user,erroringuarderror==nilelse{return}guardletuser=userelse{return}// Get the access token to attach it to a REST or gRPC request.letaccessToken=user.accessToken.tokenString// Or, get an object that conforms to GTMFetcherAuthorizationProtocol for// use with GTMAppAuth and the Google APIs client library.letauthorizer=user.fetcherAuthorizer()}
উদ্দেশ্য-C
[currentUserrefreshTokensIfNeededWithCompletion:^(GIDGoogleUser*_Nullableuser,NSError*_Nullableerror){if(error){return;}if(user==nil){return;}// Get the access token to attach it to a REST or gRPC request.NSString*accessToken=user.accessToken.tokenString;// Or, get an object that conforms to GTMFetcherAuthorizationProtocol for// use with GTMAppAuth and the Google APIs client library.id<GTMFetcherAuthorizationProtocol>authorizer=[userfetcherAuthorizer];}];
API কল করতে অ্যাক্সেস টোকেন ব্যবহার করুন, হয় একটি REST বা gRPC অনুরোধের শিরোনামে অ্যাক্সেস টোকেন অন্তর্ভুক্ত করে ( Authorization: Bearer ACCESS_TOKEN ), অথবা Google APIs ক্লায়েন্ট লাইব্রেরির সাথে ফেচার অনুমোদনকারী ব্যবহার করে।
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2025-07-25 UTC-তে শেষবার আপডেট করা হয়েছে।"],[[["\u003cp\u003eGoogle services like Drive and Gmail offer public APIs for building apps that interact with user data, requiring OAuth 2.0 for user consent and access tokens.\u003c/p\u003e\n"],["\u003cp\u003eBefore making API calls, verify granted scopes using \u003ccode\u003egrantedScopes\u003c/code\u003e and request additional scopes if needed with \u003ccode\u003eaddScopes\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eEnsure API calls have unexpired access tokens by wrapping them in \u003ccode\u003erefreshTokensIfNeededWithCompletion\u003c/code\u003e to refresh tokens.\u003c/p\u003e\n"],["\u003cp\u003eAccess tokens can be used directly in REST/gRPC requests or with the Google APIs Client Library for seamless integration.\u003c/p\u003e\n"],["\u003cp\u003eBasic Google Sign-In integration is a prerequisite before using these features.\u003c/p\u003e\n"]]],[],null,["# Access Google APIs in an iOS app\n\nSome Google services, such as Drive, Gmail, and many others, provide public APIs\nthat you can use to create apps that help users work with their data in these\nservices. To access these services, apps must implement one of the OAuth 2.0\nclient flows to get consent from users and obtain *access tokens*, which grant\naccess to the APIs.\n\nYou can use the Google Sign-In library, which implements the OAuth 2.0 flow for\nyou, to get access tokens for the signed-in user.\n\nBefore you begin\n----------------\n\nYou must complete the [basic Google Sign-In integration](/identity/sign-in/ios/sign-in).\n\n1. Check which scopes have been granted\n---------------------------------------\n\nBefore you make a call to a Google API, check which scopes have already been\ngranted to your app, using the `grantedScopes` property of `GIDGoogleUser`: \n\n### Swift\n\n let driveScope = \"https://www.googleapis.com/auth/drive.readonly\"\n let grantedScopes = user.grantedScopes\n if grantedScopes == nil || !grantedScopes!.contains(driveScope) {\n // Request additional Drive scope.\n }\n\n### Objective-C\n\n NSString *driveScope = @\"https://www.googleapis.com/auth/drive.readonly\";\n\n // Check if the user has granted the Drive scope\n if (![user.grantedScopes containsObject:driveScope]) {\n // request additional drive scope\n }\n\nBased on whether or not a certain scope has been granted by the user, you might\nneed to make a request for an additional scope in order to support a particular\ninteraction.\n\n2. Request additional scopes\n----------------------------\n\nIf you need to request additional scopes, call\n`addScopes:presentingViewController:completion` or\n`addScopes:presentingWindow:completion` to ask the user to grant your app\nadditional access.\n\nFor example, to request read-only access to a user's Drive files: \n\n### Swift\n\n let additionalScopes = [\"https://www.googleapis.com/auth/drive.readonly\"]\n guard let currentUser = GIDSignIn.sharedInstance.currentUser else {\n return ; /* Not signed in. */\n }\n\n currentUser.addScopes(additionalScopes, presenting: self) { signInResult, error in\n guard error == nil else { return }\n guard let signInResult = signInResult else { return }\n\n // Check if the user granted access to the scopes you requested.\n }\n\n### Objective-C\n\n NSArray *additionalScopes = @[ @\"https://www.googleapis.com/auth/drive.readonly\" ];\n GIDGoogleUser *currentUser = GIDSignIn.sharedInstance.currentUser;\n\n [currentUser addScopes:additionalScopes\n presentingViewController:self\n completion:^(GIDSignInResult * _Nullable signInResult,\n NSError * _Nullable error) {\n if (error) { return; }\n if (signInResult == nil) { return; }\n\n // Check if the user granted access to the scopes you requested.\n }];\n\n3. Make an API call with fresh tokens\n-------------------------------------\n\nTo ensure that your Google API calls always have unexpired access tokens\nattached, wrap the calls in a `refreshTokensIfNeededWithCompletion:` block: \n\n### Swift\n\n currentUser.refreshTokensIfNeeded { user, error in\n guard error == nil else { return }\n guard let user = user else { return }\n\n // Get the access token to attach it to a REST or gRPC request.\n let accessToken = user.accessToken.tokenString\n\n // Or, get an object that conforms to GTMFetcherAuthorizationProtocol for\n // use with GTMAppAuth and the Google APIs client library.\n let authorizer = user.fetcherAuthorizer()\n }\n\n### Objective-C\n\n [currentUser refreshTokensIfNeededWithCompletion:^(\n GIDGoogleUser * _Nullable user,\n NSError * _Nullable error) {\n if (error) { return; }\n if (user == nil) { return; }\n\n // Get the access token to attach it to a REST or gRPC request.\n NSString *accessToken = user.accessToken.tokenString;\n\n // Or, get an object that conforms to GTMFetcherAuthorizationProtocol for\n // use with GTMAppAuth and the Google APIs client library.\n id\u003cGTMFetcherAuthorizationProtocol\u003e authorizer = [user fetcherAuthorizer];\n }];\n\nUse the access token to call the API, by either including the access token in\nthe header of a REST or gRPC request (`Authorization: Bearer `\u003cvar translate=\"no\"\u003eACCESS_TOKEN\u003c/var\u003e),\nor by using the fetcher authorizer with the\n[Google APIs Client Library](https://github.com/google/google-api-objectivec-client-for-rest/)."]]