Reputation: 49
while following this tutorial : https://www.youtube.com/watch?v=IBhdLRheKyM
I ran into a problem and i've tried several things like replacing apiclient.discovery with googleapiclient.discovery. Didn't work.
type(resource) and len(result['items'] return void. PyCharm states that there an unresolved reference.
Cannot find reference 'discovery' in '__init__.py'
i installed the module using the pip tool. (pip install google-api-python-client) which prompted no issues whatsoever.
Example code:
from apiclient.discovery import build
api_key = "api_key"
resource = build("customsearch", 'v1', developerKey=api_key).cse()
result = resource.list(q='alfa romeo', cx="searchengineID").execute()
type(resource)
len(result['items'])
>> Process finished with exit code 0
edited out the api_key and cx as it's sensitive information.
'init.py' source:
"""Retain apiclient as an alias for googleapiclient."""
from six import iteritems
import googleapiclient
from googleapiclient import channel
from googleapiclient import discovery
from googleapiclient import errors
from googleapiclient import http
from googleapiclient import mimeparse
from googleapiclient import model
try:
from googleapiclient import sample_tools
except ImportError:
# Silently ignore, because the vast majority of consumers won't use it and
# it has deep dependence on oauth2client, an optional dependency.
sample_tools = None
from googleapiclient import schema
__version__ = googleapiclient.__version__
_SUBMODULES = {
'channel': channel,
'discovery': discovery,
'errors': errors,
'http': http,
'mimeparse': mimeparse,
'model': model,
'sample_tools': sample_tools,
'schema': schema,
}
import sys
for module_name, module in iteritems(_SUBMODULES):
sys.modules['apiclient.%s' % module_name] = module
Upvotes: 0
Views: 726
Reputation: 6441
Hmm. Pasting that exact code (replacing the API key and CX) worked for me into a shell worked for me in both Python 2.7 and 3.5.
Normally if apiclient.discovery.build()
fails, it will raise an exception, rather than returning an invalid value.
What do you mean when you say "type(resource) and len(result['items'] return void"? As void isn't a type in Python, did you mean <class 'NoneType'>
?
Also, what does type(result)
return?
Upvotes: 1