示例#1
0
 async def before_refresh_calendar(self):
     with open(self.bot.config.GOOGLE_CREDS_FILE) as f:
         self.creds = ServiceAccountCreds(
             scopes=[
                 "https://www.googleapis.com/auth/calendar.events.readonly"
             ],
             **json.load(f),
         )
 async def loadasyncsheetservice(self, serviceAccountFile):
     with open(serviceAccountFile, "r") as read_file:
         SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
         credfile = json.load(read_file)
         asynccreds = None
         asynccreds = ServiceAccountCreds(scopes=SCOPES, **credfile)
         async with Aiogoogle(
                 service_account_creds=asynccreds) as aiogoogle:
             self._sheetServiceAsync = await aiogoogle.discover(
                 "sheets", "v4")
         self._spreadsheetAsync = self._sheetServiceAsync.spreadsheets
         self.aiogoogle = aiogoogle
#!/usr/bin/python3.7
"""Upload files to Google Cloud Storage using asynchronous calls"""

from typing import List, Dict, Tuple
import asyncio

from aiogoogle import Aiogoogle
from aiogoogle.auth.creds import ServiceAccountCreds

creds = ServiceAccountCreds(scopes=[
    "https://www.googleapis.com/auth/devstorage.read_only",
    "https://www.googleapis.com/auth/devstorage.read_write",
    "https://www.googleapis.com/auth/devstorage.full_control",
    "https://www.googleapis.com/auth/cloud-platform.read-only",
    "https://www.googleapis.com/auth/cloud-platform",
], )

aiogoogle_factory = Aiogoogle(service_account_creds=creds)


async def get_creds():
    """Set up the credentials for aiogoogle"""
    await aiogoogle_factory.service_account_manager.detect_default_creds_source(
    )


asyncio.run(get_creds())


async def async_gcs(file_list: List[Tuple[str, str, str]], bucket: str):
    async with aiogoogle_factory:
示例#4
0
"""
aiogoogle utilities for finding and creating folders in Google Drive
"""
import asyncio
import json
from typing import Optional

from aiogoogle import Aiogoogle
from aiogoogle.auth.creds import ServiceAccountCreds

# Not sure if this can be consolidated with the gspread_asyncio credentials?
creds = ServiceAccountCreds(scopes=["https://www.googleapis.com/auth/drive"],
                            **json.load(open("google_secrets.json")))


async def create_folder(name: str, parent_id: Optional[str] = None) -> dict:
    aiogoogle = Aiogoogle(service_account_creds=creds)
    async with aiogoogle:
        drive_v3 = await aiogoogle.discover("drive", "v3")
        payload = {
            "name": name,
            "mimeType": "application/vnd.google-apps.folder"
        }
        if parent_id:
            payload["parents"] = [parent_id]
        result = await aiogoogle.as_service_account(
            drive_v3.files.create(json=payload, fields="id"))
    return result  # {"id": ".. folder_id .."}


async def find_folder(name: str, parent_id: str) -> dict:
import json
from pprint import pprint
import asyncio
from aiogoogle import Aiogoogle
from aiogoogle.auth.creds import ServiceAccountCreds
'''
https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.products/get
'''

service_account_key = json.load(open('test_service_account.json'))

creds = ServiceAccountCreds(
    scopes=['https://www.googleapis.com/auth/androidpublisher'],
    **service_account_key)


async def verify_purchase(token, package_name, product_id):
    async with Aiogoogle(service_account_creds=creds) as aiogoogle:
        publisher_api = await aiogoogle.discover('androidpublisher', 'v3')

        request = publisher_api.purchases.products.get(
            token=token, productId=product_id, packageName=package_name)

        validation_result = await aiogoogle.as_service_account(
            request, full_res=True, raise_for_status=False)
    pprint(validation_result.content)


if __name__ == "__main__":
    asyncio.run(
        verify_purchase(token='replace_this_with_your_token',
示例#6
0
import json
from pprint import pprint
import asyncio
from aiogoogle import Aiogoogle
from aiogoogle.resource import GoogleAPI
from aiogoogle.auth.creds import ServiceAccountCreds
import aiohttp


service_account_key = json.load(open('test_service_account.json'))

creds = ServiceAccountCreds(
    scopes=[
        "https://www.googleapis.com/auth/keep",
        "https://www.googleapis.com/auth/keep.readonly",
    ],
    **service_account_key
)

DISCOVERY_DOC_URL = 'https://keep.googleapis.com/$discovery/rest?version=v1'


async def list_notes():
    async with Aiogoogle(service_account_creds=creds) as aiogoogle:
        async with aiohttp.ClientSession() as session:
            async with session.get(DISCOVERY_DOC_URL) as resp:
                disc_doc = await resp.json()
        keep = GoogleAPI(disc_doc)
        res = await aiogoogle.as_service_account(keep.notes.list())
        pprint(res)