API Google. Ejemplos

Re: API Google. Ejemplos

Postby jorjio » Mon Sep 21, 2015 9:26 am

softruz wrote:Muy buenas Compañeros,
abro este hilo para compartir todo lo que sepamos sobre la API de Google, en este caso comparto una pequeña parte de la API de Google Calendar, para poder leer y insertar eventos en nuestros calendarios.

Teneis que configurar las variables myEmail (email de gmail),myPassword (password del email)

Si teneis mas informacion



////////////////////////////////
// Codigo Fuente
////////////////////////////

#include "FiveWin.ch"

Function Main()
local strURL:= "https://www.google.com/accounts/ClientLogin",AuthCode:=""
local strFormData,myEmail:="",myPassword:="",mySource:="project-example-1",cRespone:=""
strFormData = "Email=" + myEmail + "&Passwd=" + myPassword + "&source=" + mySource + "&service=cl"
cResponse:=SendPostToUrl( strURL, strFormData )
AuthCode = Right(cResponse, Len(cResponse) - at("Auth=",cResponse) - 4)

cEventCode:=getEventCode(date(),"Test Event","Event Description","Your Name","Email","Cordoba")

// Añadir un nuevo evento
strURL = "http://www.google.com/calendar/feeds/default/private/full"
strFormData = cEventCode
cResponse:=SendPostToUrl( strURL, strFormData,"application/atom+xml","GoogleLogin auth=" + AuthCode)

// Recivir los calendarios
strURL:="https://www.google.com/calendar/feeds/default/allcalendars/full"
strFormData = cEventCode
cResponse:=SendPostToUrl( strURL, strFormData,"application/atom+xml","GoogleLogin auth=" + AuthCode)
msginfo(cResponse)
Return Nil

Function SendPostToUrl( cUrl, cParams,cContentType,cAuthorization )
Local oOle,cRet:='',uRet
default cContentType:="application/x-www-form-urlencoded"
default cAuthorization:=""
Try
oOle := CreateObject( 'MSXML2.XMLHTTP' )
Catch
oOle := CreateObject( 'Microsoft.XMLHTTP' )
End
oOle:Open( 'POST', cUrl, .f. )

oOle:SetRequestHeader( "Content-Type",cContentType)
if !empty(cAuthorization)
oOle:SetRequestHeader( "Authorization",cAuthorization)
end if

oOle:Send( cParams )
SysRefresh()

#ifdef __XHARBOUR__
cRet := oOle:ResponseBody
#else
AEval(oOle:ResponseBody,{|uRet|cRet+=Chr(uRet)})
#endif
Return cRet

function dtos_format(fecha)
local cadena
if valtype(fecha) = "D"
cadena:=dtos(fecha)
if !empty(cadena)
return substr(cadena,1,4) + "-" + substr(cadena,5,2) + "-" + substr(cadena,7,2)
else
return "0000-00-00"
end if
else
return "0000-00-00"
end if
return "0000-00-00"

static function getEventCode(dDate,cEventName,cEventDescription,cYourName,cEmailAddress,cLocation,cStartTime,cEndTime)
local formattedDate:=""
default cStartTime:="17:00:00",cEndTime:="18:00:00"

// 'change the date into Google's yyyy-mm-dd format
formattedDate = dtos_format(dDate)

getEventCode = "<entry xmlns='http://www.w3.org/2005/Atom'" + CRLF +;
"xmlns:gd='http://schemas.google.com/g/2005'>" + CRLF +;
" <category scheme='http://schemas.google.com/g/2005#kind'" + CRLF +;
"term='http://schemas.google.com/g/2005#event'></category>" + CRLF +;
" <title type='text'>" +cEventName+ "</title>" + CRLF +;
"<content type='text'>" +cEventDescription+ "</content>" + CRLF +;
"<author>" + CRLF +;
"<name>" +cYourName+ "</name>" + CRLF +;
"<email>" +cEmailAddress+ "</email>" + CRLF +;
"</author>" + CRLF +;
"<gd:transparency" + CRLF +;
"value='http://schemas.google.com/g/2005#event.opaque'>" + CRLF +;
"</gd:transparency>" + CRLF +;
"<gd:eventStatus" + CRLF +;
"value='http://schemas.google.com/g/2005#event.confirmed'>" + CRLF +;
"</gd:eventStatus>" + CRLF +;
"<gd:where valueString='" +cLocation+ "'></gd:where>" + CRLF +;
"<gd:when startTime='" + formattedDate + "T" + cStartTime+"'" + CRLF +;
"endTime='" + formattedDate + "T" + cEndTime+"'></gd:when>" + CRLF +;
"</entry>"
return getEventCode


Hi,
It is very good. I have tried it and works fine. I can not make it work with MTOM attached file. Do you know how we do it?
jorjio
 
Posts: 14
Joined: Tue Sep 10, 2013 8:08 pm

Previous

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 51 guests