1

I am trying a create an google calendar event using API...But i am getting error while trying to create event..I am getting access token succesfully but not able to create calendar events...

Please help i am trying to sort out this from the last 2 days...I think this is some perrmision issue...I am using below scope.

any help will be highly appreciated.

String scope='https://www.googleapis.com/auth/calendar';

            Http h = new Http();
            string calendarId='a@b.com';
            string url='https://www.googleapis.com/calendar/v3/calendars/'+calendarId+'/events';
            string body='{"end":{"date": "2013-06-21"},"start":{"date": "2013-06-20"}}';
            HttpRequest req=new HttpRequest();
             System.debug('-----accesstokenvvvvvvvv---'+accesstoken);
            req.setHeader('Authorization','Bearer '+accesstoken);
            req.setHeader('Content-Type', 'application/json');
            req.setEndpoint(url);
            req.setBody(body);
            System.debug('-----body---'+body);
            req.setMethod('POST');
            HttpResponse res;
            res = h.send(req);
            string data=res.getBody();
            System.debug('--------data----'+data);

I am getting error response

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "insufficientPermissions",
    "message": "Insufficient Permission"
   }
  ],
  "code": 403,
  "message": "Insufficient Permission"
 }
}
  • Might be a duplicate of http://stackoverflow.com/questions/16970917/why-is-google-calendar-api-oauth2-responding-with-insufficient-permission – rob_mccann Aug 06 '13 at 11:33

1 Answers1

0

The problem (I assume) is that you haven't registered your API under the Remote Site Settings. Despite Google's tight relationship with salesforce.com this is still necessary for you to perform Http CallOuts.

-Setup
-Security Controls
-Remote Site Settings

Here just add a new remote site and provide the Remote Site URL of the endpoint. In your case it would just be "https://www.googleapis.com".

If this response was slow, I'd recommend using https://salesforce.stackexchange.com for posting questions and searching for answers. There you will find much more APEX and salesforce devs.

Hope this helps!

Whiteout
  • 31
  • 3