0

I am new to google python api client.I am learning from https://developers.google.com/api-client-library/python/start/get_started.I want to make an api which converts python object into JSON data and sends to a servlet.

The python code of file api.py:

import os
import urllib2
import httplib2
import json
import requests
from apiclient.discovery import build
from oauth2client.client import flow_from_clientsecrets
from oauth2client.tools import run_flow
from oauth2client.file import Storage
from oauth2client import tools

api_version='1'
_file_="D:\API"


CLIENT_SECRETS = os.path.join(os.path.dirname(_file_))

flow=flow_from_clientsecrets(CLIENT_SECRETS,
  scope=[
      'https://www.googleapis.com/auth/devstorage.full_control',
      ],


http = httplib2.Http()
auth_http = credentials.authorize(http)

service=build('SendNotif',api_version,http=http)

req = urllib2.Request('http://example/notify')
req.add_header('Content-Type', 'application/json')

data={"message":"Hello User you are notified"}
data_json = json.dumps(data)

response = urllib2.urlopen(req, json.dumps(data))

The error shown is:

    D:\API>python api.py
    File "api.py", line 25
    auth_http = credentials.authorize(http)
        ^
    SyntaxError: invalid syntax

please do help in correcting me.. thanks in advance....

1 Answers1

0

You're missing a closing parenthesis for this line:

flow=flow_from_clientsecrets(CLIENT_SECRETS,
Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129
  • Now it displays... ` ile "D:\API\try.py", line 76, in main(sys.argv) File "D:\API\try.py", line 62, in main service = build(api_name,api_version,http=http) File "D:\Python27\lib\site-packages\oauth2client\util.py", line 135, in positional_wrapper return wrapped(*args, **kwargs) File "D:\Python27\lib\site-packages\googleapiclient\discovery.py", line 202, in build version)) UnknownApiNameOrVersion: name: send version: v1` – Chaitanya Joshi Feb 03 '15 at 11:25
  • Read https://developers.google.com.com/api-client-library/python/apis/ the api version should be either v1 or v2, not 1. For future reference, if you have another question post it as a new question – Nir Alfasi Feb 03 '15 at 14:23