Google provides a Node.js client library for interacting with the Ad Manager API.
পূর্বশর্ত
To use the Node.js client library, you must have Node.js installed. For more information, see Download Node.js® .
ক্লায়েন্ট লাইব্রেরি ইনস্টল করুন
To get started, create a new project in the IDE of your choice or add the dependency to an existing project. Google publishes client library artifacts to npm as @google-ads/admanager .
প্যাকেজ.json
"dependencies": {
"@google-ads/admanager": "^0.4.0"
}
কমান্ড লাইন
npm install @google-ads/admanager
পরিচয়পত্র কনফিগার করুন
To authenticate, the Node.js client library uses OAuth2 and Application Default Credentials (ADC). For creating and configuring your ADC credentials, see Authentication .
আপনার প্রথম অনুরোধটি করুন
প্রতিটি সার্ভিসের একটি ServiceClient অবজেক্ট থাকে, যেখানে প্রতিটি REST মেথডের জন্য মেথডসমূহ অন্তর্ভুক্ত থাকে। প্রতিটি মেথডের উদাহরণের জন্য, googleapis/google-cloud-node গিটহাব রিপোজিটরিটি দেখুন। নিম্নলিখিত উদাহরণটি একটি Network অবজেক্ট রিড করে:
// Resource name of the Network
const name = 'networks/NETWORK_CODE'
// Imports the Admanager library
const {NetworkServiceClient} = require('@google-ads/admanager').v1;
// Instantiates a client
const admanagerClient = new NetworkServiceClient();
async function callGetNetwork() {
// Construct request
const request = {
name,
};
// Run request
const response = await admanagerClient.getNetwork(request);
console.log(response);
}
callGetNetwork();
HTTP অনুরোধ এবং প্রতিক্রিয়া লগ করুন
The Node.js client library supports logging HTTP requests and responses. By default, the client library disables logging.
স্ট্যান্ডার্ড আউটপুটে ডিফল্ট লগিং চালু করতে, GOOGLE_SDK_NODE_LOGGING এনভায়রনমেন্ট ভেরিয়েবলটিকে গুগল এপিআই প্যাকেজের নামগুলোর একটি কমা-বিভক্ত তালিকা হিসেবে সেট করুন। ভেরিয়েবলের মান ' all সেট করে আপনি সমস্ত গুগল এপিআই-এর জন্য লগিং চালু করতে পারেন। সমস্ত উপলব্ধ ক্লায়েন্ট লাইব্রেরি প্যাকেজের নাম জানতে, Google Cloud Node.js Client Libraries দেখুন।
নোড.জেএস
// Enable logging for the Google Ad Manager API
process.env.GOOGLE_SDK_NODE_LOGGING = 'admanager';
// Enable logging for the Google Ad Manager and pubsub APIs.
process.env.GOOGLE_SDK_NODE_LOGGING = 'admanager,pubsub';
// Enable logging for all Google APIs
process.env.GOOGLE_SDK_NODE_LOGGING = 'all';
লিনাক্স বা ম্যাকওএস
# Enable logging for the Google Ad Manager API.
export GOOGLE_SDK_NODE_LOGGING=admanager
# Enable logging for the Google Ad Manager and pubsub APIs.
export GOOGLE_SDK_NODE_LOGGING=admanager,pubsub
# Enable logging for all Google APIs
export GOOGLE_SDK_NODE_LOGGING=all
উইন্ডোজ
# Enable logging for the Google Ad Manager API.
set GOOGLE_SDK_NODE_LOGGING=admanager
# Enable logging for the Google Ad Manager and pubsub APIs.
set GOOGLE_SDK_NODE_LOGGING=admanager,pubsub
# Enable logging for all Google APIs
set GOOGLE_SDK_NODE_LOGGING=all
Alternatively, you can change the logging backend or hook log events. For more information, see Google Logging Tools .
ত্রুটিগুলি পরিচালনা করুন
In the Node.js client library, all Ad Manager API errors throw an exception of type GaxiosError .
অ্যাড ম্যানেজার এপিআই ত্রুটিগুলিতে একটি ত্রুটি বার্তা এবং একটি অনন্য requestId মান অন্তর্ভুক্ত থাকে যা আপনি এপিআই সাপোর্ট টিমকে প্রদান করতে পারেন। সমস্যা সমাধানে সহায়তার জন্য, এপিআই সাপোর্টের সাথে যোগাযোগ করুন দেখুন। নিম্নলিখিত উদাহরণটি requestId মান এবং ত্রুটি বার্তাটি বের করে:
const admanagerClient = new NetworkServiceClient();
try {
const network = admanagerClient.getNetwork(
{ name: 'networks/NETWORK_CODE' }
);
console.log(network);
} catch(e) {
if (e instanceof GaxiosError) {
// Load the error
const apiError = JSON.parse(e.message).error;
const requestInfoType = 'type.googleapis.com/google.rpc.RequestInfo';
const requestInfo = apiError.details.find(detail => detail['@type'] === requestInfoType);
console.error(apiError.status + ' - ' + apiError.message);
console.error('RequestId: ' + requestInfo.requestId);
} else {
throw e;
}
}