مستندات API جستجوی گوگل (API Google Search)

مستندات وب سرویس (API) جستجوی گوگل را میتوانید از طریق این صفحه به میزبانی مجموعه تاک بات مشاهده کنید. و از آنها در پروژه های خود استفاده کنید. این سیستم به صورت تخصصی و بدون مشکل توسط تاک بات در کنار سایر خدمات مبتنی بر هوش مصنوعی ارائه می شود.

برای امکان استفاده از این وب سرویس لازم است بسته یاقوتی روی حساب کاربری شما فعال باشد. با خرید بسته یاقوتی شما میتوانید علاوه بر امکان دسترسی به خدمات تخصصی هوش مصنوعی، و ارتباط با آخرین نسل ها، و ضمن امکان بهره گیری از API تبدیل متن به صوت، و API GPT-4 و Gemini Pro و ... از این سرویس نیز استفاده کنید.

نحوه ارسال درخواست

برای ارسال یک درخواست به API، باید URL مورد نظر را به صورت درخواست HTTP POST ارسال کنید.

$url = 'https://api.talkbot.ir/v1/search/google/web';

سربرگ‌ها

برای تنظیم سربرگ Authorization، باید توکن Bearer خود را استفاده کنید.

$headers = [
    'Authorization: Bearer YOUR_ACCESS_TOKEN'
];

داده‌های POST

برای ارسال درخواست POST، باید این داده‌ها را به عنوان بخشی از بدنه ارسال کنید:

$data = [
    'text' => 'Your Search Text',
    'gl' => 'ir',   // Geographical location: Iran or other
    'nl' => 'fa',   // Natural Language: Persian or other
    'page' => '1',  // Search Page number
    'num' => '10',  // Number of results per page
];

ارسال درخواست

برای ارسال درخواست، می‌توانید از cURL در PHP استفاده کنید:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if(curl_errno($ch)){
    echo 'error CURL: ' . curl_error($ch);
}
curl_close($ch);

یک مثال برای درخواست با PHP:

یک نمونه درخواست وجود دارد که شما می توانید API خود را جایگزین کنید.



$headers = [
    'Authorization: Bearer sk-s68980b7df06c90b558092fawebff9as'
];
$data = [
    'text' => 'What is google api talkbot ?',
    'gl' => 'ir',  
    'nl' => 'fa',  
    'page' => '1', 
    'num' => '10',  
];
$url = 'https://api.talkbot.ir/v1/search/google/web';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo $response = curl_exec($ch);
if(curl_errno($ch)){
    echo 'error CURL: ' . curl_error($ch);
}
curl_close($ch);
	

پاسخ API

پاسخ شامل یک رشته JSON می باشد. که شامل نتایج جستجوی صفحه موردنظر گوگل می باشد. این نتایج به صورت زنده ارائه می شوند.

یک مثال برای خروجی:

اینجا یک نمونه خروجی وب سرویس گوگل ، ارائه شده توسط تاک بات وجود دارد:


{
  "knowledgeGraph": {
    "title": "Google Search",
    "type": "Website",
    "website": "https://google.com/",
    "imageUrl": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTmIN-ig-CYut49zgv_OgPnqThWsg2BCotm216cyQrdDuNvi0zzbyEWBA&s=0",
    "description": "Google Search is a search engine provided and operated by Google. Handling more than 3.5 billion searches per day, it has a 92% share of the global search engine market. It is the most-visited website in the world. Additionally, it is the most...",
    "descriptionSource": "Wikipedia",
    "descriptionLink": "https://en.wikipedia.org/wiki/Google_Search",
    "attributes": {
      "Written in": "Python, C, and C++",
      "Category": "Search engine",
      "Date launched": "1998"
    }
  },
  "organic": [
    {
      "title": "Google",
      "link": "https://www.google.com/?gws_rd=ssl",
      "snippet": "Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking ...",
      "sitelinks": [
        {
          "title": "My Activity",
          "link": "https://myactivity.google.com/"
        },
        {
          "title": "Images",
          "link": "https://images.google.com/"
        },
        {
          "title": "Photos",
          "link": "https://www.google.com/photos/about/"
        },
        {
          "title": "Search",
          "link": "https://www.google.com/search/howsearchworks/"
        }
      ],
      "position": 1
    },
    {
      "title": "Google Search - Stay in the Know with Your Google App",
      "link": "https://www.google.com/search/about/",
      "snippet": "Discover keeps you up to date on all your favorite topics. Follow everything from sports teams and movies to celebrities, hobbies, and more. Plus, you can dive ...",
      "position": 2
    },
    {
      "title": "Google Search Console Tools",
      "link": "https://search.google.com/search-console/about",
      "snippet": "Search Console tools and reports help you measure your site's Search traffic and performance, fix issues, and make your site shine in Google Search results.",
      "position": 3
    },
    {
      "title": "Google Search Help",
      "link": "https://support.google.com/websearch/?hl=en",
      "snippet": "Official Google Search Help Center where you can find tips and tutorials on using Google Search and other answers to frequently asked questions.",
      "position": 4
    },
    {
      "title": "Google Search - Wikipedia",
      "link": "https://en.wikipedia.org/wiki/Google_Search",
      "snippet": "Google Search is a search engine provided and operated by Google. Handling more than 3.5 billion searches per day, it has a 92% share of the global search ...",
      "attributes": {
        "Available in": "149 languages",
        "URL": "www.google.com"
      },
      "position": 5
    },
    {
      "title": "Welcome to My Activity - Google",
      "link": "https://myactivity.google.com/",
      "snippet": "Welcome to My Activity. Data helps make Google services more useful for you. Sign in to review and manage your activity, including things you've searched ...",
      "position": 6
    },
    {
      "title": "Your data in Search - Google Account",
      "link": "https://myaccount.google.com/intro/yourdata/search?hl=en-US",
      "snippet": "Your Search history is saved to your Google Account as part of your Web & App Activity, along with activity from other Google services. Signed-out Search ...",
      "position": 7
    },
    {
      "title": "Google Trends",
      "link": "https://trends.google.com/trends/",
      "snippet": "See how Google Trends is being used across the world, by newsrooms, charities, and more. Local Year in Search. Explore searches in your zipcode.",
      "position": 8
    },
    {
      "title": "What Google Search Isn't Showing You | The New Yorker",
      "link": "https://www.newyorker.com/culture/infinite-scroll/what-google-search-isnt-showing-you",
      "snippet": "The search engine has made up so much of our online experience for so long that it can be hard to imagine something better.",
      "date": "Mar 10, 2022",
      "position": 9
    },
    {
      "title": "Google",
      "link": "https://images.google.com/",
      "snippet": "Google Images. The most comprehensive image search on the web.",
      "position": 10
    }
  ],
  "peopleAlsoAsk": [
    {
      "question": "How do I get Google to search?",
      "snippet": "Navigate to google.com and type your query into the search box. Then, hit\nsearch. You can filter your results by web page, image, shopping, videos, etc.",
      "title": "3 Ways to Search Google - wikiHow",
      "link": "https://www.wikihow.com/Search-Google"
    },
    {
      "question": "Can you find out if you have been Googled?",
      "snippet": "The most popular site is Google Alerts, but there are others like Mention.com\nthat you can use if you prefer. Google Alerts will prompt you to enter your name\nand any other words relevant to your reputation. You can also enter your name\nand keywords into our free privacy scan on our website.",
      "title": "How can I know if someone searched my name on Google? - Reputation.ca",
      "link": "https://www.reputation.ca/how-can-i-know-if-someone-searched-my-name-on-google/"
    }
  ],
  "relatedSearches": [
    {
      "query": "Google Search Console login"
    },
    {
      "query": "www.google.com in"
    },
    {
      "query": "Google sign in"
    },
    {
      "query": "Google Search Console"
    },
    {
      "query": "Google Lens"
    },
    {
      "query": "Google Mail"
    },
    {
      "query": "Google Chrome"
    },
    {
      "query": "Google map"
    }
  ]
}
	

نام مدل هزینه (TPU)
Google Search 250TPU
موجودی توکن نیاز به ورود
TPU (توکن به ازای هر درخواست)
TPU = Token Per Use

آزمایش رایگان:

برای آزمایش و تست رایگان این وب سرویس (API) ابتدا در سایت ثبتنام کنید، و سپس از طریق کنترل پنل کاربری، کلید اختصاصی خود را ایجاد کنید. پس از ایجاد کلید، آن را در نمونه کدهای بالا جایگزاری کرده و خروجی را مشاهده کنید. امکان استفاده از کلید آزمایشی فقط تا 15000 توکن میسر است.


سایر وب سرویس ها:

با خرید بسته و بسته های فرایاقوتی، شما علاوه بر وب سرویس یا API پیش رو، از وب سرویس های زیر نیز میتوانید استفاده کنید.