function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sreenathsreenath 

http errors in callout

Hi developers,

                  I am getting 302, 401 & 404 status code errors from authentication to google api. what i am missing please help me 

                 

public class GoogleCalendar
{
public void detail()
{
Http h = new Http();
HttpRequest req = new HttpRequest();
final string username = 'sreenath.sfdc@gmail.com';
final string password = 'Password';
//final string apikey='AIzaSyDaQK60dlM-7icVukY0sbaOHae9eLn3dKk';
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'BASIC ' +EncodingUtil.base64Encode(headerValue);
// auth url is https://www.googleapis.com/auth/calendar
req.setHeader('Authorization',authorizationHeader);
req.setHeader('Connection','keep-alive');
req.setHeader('Host','googleapis.com');
req.setHeader('Content-Type', 'application/Json');
req.setMethod('GET');
req.setbody('https://www.googleapis.com/auth/calendar?key=AIzaSyDaQK60dlM-7icVukY0sbaOHae9eLn3dKk');
//req.setbody(apikey);
req.setEndpoint('https://www.googleapis.com/calendar/v3/calendars/calendarId');
//req.setEndpoint('https://www.googleapis.com/calendar/v3/calendars/sreenath.sfdc@gmail.com/events/tea%20time?pp=1&key=AIzaSyDaQK60dlM-7icVukY0sbaOHae9eLn3dKk');
HttpResponse res = h.send(req);
system.debug('********'+res.getbody());
}


}

sreenathsreenath

please find my log for issues, help me out 

 

 

24.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
04:59:21.027 (27353000)|EXECUTION_STARTED
04:59:21.027 (27392000)|CODE_UNIT_STARTED|[EXTERNAL]|066900000013lY8|VF: /apex/Googlecalendar
04:59:21.028 (28125000)|VF_DESERIALIZE_VIEWSTATE_BEGIN|066900000013lY8
04:59:21.031 (31911000)|VF_DESERIALIZE_VIEWSTATE_END
04:59:21.034 (34135000)|CODE_UNIT_STARTED|[EXTERNAL]|01p900000014BMk|GoogleCalendar invoke(detail)
04:59:21.034 (34567000)|METHOD_ENTRY|[1]|01p900000014BMk|GoogleCalendar.GoogleCalendar()
04:59:21.034 (34576000)|STATEMENT_EXECUTE|[1]
04:59:21.034 (34694000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
04:59:21.034 (34705000)|STATEMENT_EXECUTE|[1]
04:59:21.034 (34720000)|METHOD_EXIT|[1]|GoogleCalendar
04:59:21.034 (34733000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
04:59:21.034 (34743000)|VARIABLE_SCOPE_BEGIN|[3]|this|GoogleCalendar|true|false
04:59:21.034 (34767000)|VARIABLE_ASSIGNMENT|[3]|this|{}|0x1783c570
04:59:21.034 (34782000)|HEAP_ALLOCATE|[5]|Bytes:5
04:59:21.034 (34787000)|STATEMENT_EXECUTE|[4]
04:59:21.034 (34791000)|STATEMENT_EXECUTE|[5]
04:59:21.034 (34832000)|VARIABLE_SCOPE_BEGIN|[5]|h|System.Http|true|false
04:59:21.034 (34964000)|VARIABLE_ASSIGNMENT|[5]|h|"System.Http[]"|0xbd89c68
04:59:21.034 (34973000)|STATEMENT_EXECUTE|[6]
04:59:21.034 (34995000)|VARIABLE_SCOPE_BEGIN|[6]|req|System.HttpRequest|true|false
04:59:21.035 (35075000)|VARIABLE_ASSIGNMENT|[6]|req|"System.HttpRequest[Endpoint=null, Method=null]"|0x3a0475eb
04:59:21.035 (35085000)|STATEMENT_EXECUTE|[7]
04:59:21.035 (35093000)|HEAP_ALLOCATE|[7]|Bytes:23
04:59:21.035 (35103000)|VARIABLE_SCOPE_BEGIN|[7]|username|String|false|false
04:59:21.035 (35115000)|VARIABLE_ASSIGNMENT|[7]|username|"sreenath.sfdc@gmail. (3 more) ..."
04:59:21.035 (35120000)|STATEMENT_EXECUTE|[8]
04:59:21.035 (35126000)|HEAP_ALLOCATE|[8]|Bytes:12
04:59:21.035 (35131000)|VARIABLE_SCOPE_BEGIN|[8]|password|String|false|false
04:59:21.035 (35138000)|VARIABLE_ASSIGNMENT|[8]|password|"Password"
04:59:21.035 (35142000)|STATEMENT_EXECUTE|[10]
04:59:21.035 (35147000)|HEAP_ALLOCATE|[10]|Bytes:1
04:59:21.035 (35167000)|HEAP_ALLOCATE|[10]|Bytes:24
04:59:21.035 (35175000)|HEAP_ALLOCATE|[10]|Bytes:36
04:59:21.035 (35191000)|SYSTEM_METHOD_ENTRY|[10]|Blob.valueOf(String)
04:59:21.035 (35228000)|HEAP_ALLOCATE|[10]|Bytes:36
04:59:21.035 (35236000)|HEAP_ALLOCATE|[10]|Bytes:36
04:59:21.035 (35243000)|SYSTEM_METHOD_EXIT|[10]|Blob.valueOf(String)
04:59:21.035 (35252000)|VARIABLE_SCOPE_BEGIN|[10]|headerValue|Blob|false|false
04:59:21.035 (35264000)|VARIABLE_ASSIGNMENT|[10]|headerValue|BLOB(36 bytes)
04:59:21.035 (35269000)|STATEMENT_EXECUTE|[11]
04:59:21.035 (35276000)|HEAP_ALLOCATE|[11]|Bytes:6
04:59:21.035 (35345000)|SYSTEM_METHOD_ENTRY|[11]|system.EncodingUtil.base64Encode(Blob)
04:59:21.035 (35438000)|SYSTEM_METHOD_EXIT|[11]|system.EncodingUtil.base64Encode(Blob)
04:59:21.035 (35450000)|HEAP_ALLOCATE|[11]|Bytes:54
04:59:21.035 (35457000)|VARIABLE_SCOPE_BEGIN|[11]|authorizationHeader|String|false|false
04:59:21.035 (35467000)|VARIABLE_ASSIGNMENT|[11]|authorizationHeader|"BASIC c3JlZW5hdGguc2 (34 more) ..."
04:59:21.035 (35472000)|STATEMENT_EXECUTE|[13]
04:59:21.035 (35479000)|HEAP_ALLOCATE|[13]|Bytes:13
04:59:21.035 (35507000)|SYSTEM_METHOD_ENTRY|[13]|System.HttpRequest.setHeader(String, String)
04:59:21.035 (35539000)|SYSTEM_METHOD_EXIT|[13]|System.HttpRequest.setHeader(String, String)
04:59:21.035 (35548000)|STATEMENT_EXECUTE|[14]
04:59:21.035 (35554000)|HEAP_ALLOCATE|[14]|Bytes:10
04:59:21.035 (35559000)|HEAP_ALLOCATE|[14]|Bytes:10
04:59:21.035 (35573000)|SYSTEM_METHOD_ENTRY|[14]|System.HttpRequest.setHeader(String, String)
04:59:21.035 (35595000)|SYSTEM_METHOD_EXIT|[14]|System.HttpRequest.setHeader(String, String)
04:59:21.035 (35601000)|STATEMENT_EXECUTE|[15]
04:59:21.035 (35607000)|HEAP_ALLOCATE|[15]|Bytes:9
04:59:21.035 (35615000)|HEAP_ALLOCATE|[15]|Bytes:72
04:59:21.035 (35628000)|SYSTEM_METHOD_ENTRY|[15]|System.HttpRequest.setHeader(String, String)
04:59:21.035 (35649000)|SYSTEM_METHOD_EXIT|[15]|System.HttpRequest.setHeader(String, String)
04:59:21.035 (35655000)|STATEMENT_EXECUTE|[16]
04:59:21.035 (35661000)|HEAP_ALLOCATE|[16]|Bytes:13
04:59:21.035 (35666000)|HEAP_ALLOCATE|[16]|Bytes:24
04:59:21.035 (35678000)|SYSTEM_METHOD_ENTRY|[16]|System.HttpRequest.setHeader(String, String)
04:59:21.035 (35699000)|SYSTEM_METHOD_EXIT|[16]|System.HttpRequest.setHeader(String, String)
04:59:21.035 (35705000)|STATEMENT_EXECUTE|[17]
04:59:21.035 (35711000)|HEAP_ALLOCATE|[17]|Bytes:4
04:59:21.035 (35718000)|HEAP_ALLOCATE|[17]|Bytes:14
04:59:21.035 (35734000)|SYSTEM_METHOD_ENTRY|[17]|System.HttpRequest.setHeader(String, String)
04:59:21.035 (35756000)|SYSTEM_METHOD_EXIT|[17]|System.HttpRequest.setHeader(String, String)
04:59:21.035 (35762000)|STATEMENT_EXECUTE|[18]
04:59:21.035 (35769000)|HEAP_ALLOCATE|[18]|Bytes:12
04:59:21.035 (35774000)|HEAP_ALLOCATE|[18]|Bytes:16
04:59:21.035 (35786000)|SYSTEM_METHOD_ENTRY|[18]|System.HttpRequest.setHeader(String, String)
04:59:21.035 (35807000)|SYSTEM_METHOD_EXIT|[18]|System.HttpRequest.setHeader(String, String)
04:59:21.035 (35812000)|STATEMENT_EXECUTE|[19]
04:59:21.035 (35818000)|HEAP_ALLOCATE|[19]|Bytes:3
04:59:21.035 (35831000)|SYSTEM_METHOD_ENTRY|[19]|System.HttpRequest.setMethod(String)
04:59:21.035 (35851000)|SYSTEM_METHOD_EXIT|[19]|System.HttpRequest.setMethod(String)
04:59:21.035 (35857000)|STATEMENT_EXECUTE|[20]
04:59:21.035 (35863000)|HEAP_ALLOCATE|[20]|Bytes:84
04:59:21.035 (35875000)|SYSTEM_METHOD_ENTRY|[20]|System.HttpRequest.setBody(String)
04:59:21.035 (35904000)|SYSTEM_METHOD_EXIT|[20]|System.HttpRequest.setBody(String)
04:59:21.035 (35910000)|STATEMENT_EXECUTE|[22]
04:59:21.035 (35916000)|HEAP_ALLOCATE|[22]|Bytes:125
04:59:21.035 (35929000)|SYSTEM_METHOD_ENTRY|[22]|System.HttpRequest.setEndpoint(String)
04:59:21.035 (35951000)|SYSTEM_METHOD_EXIT|[22]|System.HttpRequest.setEndpoint(String)
04:59:21.035 (35956000)|STATEMENT_EXECUTE|[24]
04:59:21.035 (35983000)|SYSTEM_METHOD_ENTRY|[24]|System.Http.send(APEX_OBJECT)
04:59:21.036 (36057000)|CALLOUT_REQUEST|[24]|System.HttpRequest[Endpoint=https://www.googleapis.com/calendar/v3/calendars/sreenath.sfdc%40gmail.com?pp=1&key={AIzaSyDaQK60dlM-7icVukY0sbaOHae9eLn3dKk}, Method=GET]
04:59:21.447 (447039000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:444
04:59:21.447 (447137000)|CALLOUT_RESPONSE|[24]|System.HttpResponse[Status=Found, StatusCode=302]
04:59:21.447 (447171000)|HEAP_ALLOCATE|[24]|Bytes:444
04:59:21.447 (447190000)|SYSTEM_METHOD_EXIT|[24]|System.Http.send(APEX_OBJECT)
04:59:21.447 (447212000)|VARIABLE_SCOPE_BEGIN|[24]|res|System.HttpResponse|true|false
04:59:21.447 (447364000)|VARIABLE_ASSIGNMENT|[24]|res|"System.HttpResponse[Status=Found, StatusCode=302]"|0x238a89f7
04:59:21.447 (447376000)|STATEMENT_EXECUTE|[25]
04:59:21.447 (447391000)|HEAP_ALLOCATE|[25]|Bytes:8
04:59:21.447 (447422000)|SYSTEM_METHOD_ENTRY|[25]|System.HttpResponse.getBody()
04:59:21.447 (447502000)|HEAP_ALLOCATE|[25]|Bytes:218
04:59:21.447 (447511000)|SYSTEM_METHOD_EXIT|[25]|System.HttpResponse.getBody()
04:59:21.447 (447533000)|HEAP_ALLOCATE|[25]|Bytes:226
04:59:21.447 (447554000)|SYSTEM_METHOD_ENTRY|[25]|System.debug(ANY)
04:59:21.447 (447567000)|USER_DEBUG|[25]|DEBUG|********

302 Moved

The document has moved
here.



adi.sfdcproadi.sfdcpro

Hi Sreenath,

 

Check the url, It seems that the url that you are using is incorrect or changed.

 

Adi.

sreenathsreenath

Hi adi,

 

          You are correct but i am using the URL's which are providing in google api's. If you know this url's please post here.

 

Thanks

sreenath

Jia HuJia Hu

I also got Status=Found, StatusCode=302.

 

In the API Access of Google apis, I cannot see any API request.

I guess the problem is how to login by http request.

 

I search the document of new version V3, but cannot find any example of how to login

google calendar with username/password/api key by Http request.

 

Anyone can help with this?

super contributorsuper contributor

I am getting the same problem with another site..

 

Any pointers ??

Cheney LiuCheney Liu
me too.