Hi Anirudh,
Thanks for your response,
I corrected my code according to your suggestions, but still when I
post xml I still have the same problem.
Token looks correct...
token=DQAAAIMAAAALsNK-
SHyrMB3yfvZW6ShfyV3SFevPK31XdgFlMAm5_y3ML8vTquYEcsU_q6cK_VKcUCbYDvC37w8XBbDSzfR1Ba6HIjiWYa1FE-
f6JR91qSYDv9rwGM_VCt4w0ZhqzzNTw2nruDJO6QSDMonUaqj0jIkzj1cC_nOrq8_pSU0rDQSX6fStMfqh1_X4htO-8VA
Error en el servidor remoto: (403) Prohibido. (number=5)
Any more suggestions?
Thanks
Sergi Doutres
On May 16, 2:46 pm, "Anirudh (Google)" <[EMAIL PROTECTED]> wrote:
> Hi Sergi,
>
> Thanks for sharing the context of your problem.
>
> To answer your queries,
> 1. Google Authentication API requires URL encoded email and password
> values. So, Server.UrlEncode("[EMAIL PROTECTED]") is OK.
> 2. The Http Header used is GoogleLogin auth=<token>
>
> Please confirm if GetToken() call is getting you a token. In case not,
> sharing the message/error code you are getting from
> the server would help us investigate the exact problem. Here is a link
> detailing server
> responses:http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#R...
>
> Also, in your code, i see a problem with:
>
> webrequest.Headers.Add(Net.HttpRequestHeader.Authorization,
> "Authorization:GoogleLogin auth=" & GetToken())
>
> When using the Add() method with two parameters, the "Authorization:"
> text is getting duplicated in the header.
> You could try running the code by removing the "Authorization:" prefix
> form the second parameter.
>
> webrequest.Headers.Add(Net.HttpRequestHeader.Authorization,
> "GoogleLogin auth=" & GetToken())
>
> -Anirudh
>
> On May 15, 8:44 pm, Sergi Doutres <[EMAIL PROTECTED]> wrote:
>
> > Hi Anirudh,
>
> > The project I have is for migrating more than 1000 e mail accounts to
> > GMail. Im sending you the whole code so you could try it And create
> > the problem
> > Please let me know what could be the problem.
>
> > '-------------
> > 'GET TOKEN
> > '-------------
>
> > Questions:
> > Server.UrlEncode("[EMAIL PROTECTED]") it's ok?
> > -----------------------------------------
>
> > Public Function GetToken() As String
>
> > Dim encoding As ASCIIEncoding = New ASCIIEncoding
>
> > Dim postdata As String = ""
> > postdata = postdata & "accountType=HOSTED"
> > postdata = postdata & "&Email=" & Server.UrlEncode("[EMAIL PROTECTED]")
> > postdata = postdata & "&Passwd=" & Server.UrlEncode("pwd")
> > postdata = postdata & "&service=apps"
>
> > Dim data As Byte() = encoding.GetBytes(postdata)
>
> > 'Prepare web request...
> > Dim myrequest As HttpWebRequest =
> > HttpWebRequest.Create("https://www.google.com/accounts/ClientLogin")
> > myrequest.Method = "POST"
> > myrequest.ContentType = "application/x-www-form-urlencoded"
> > myrequest.ContentLength = data.Length
> > Dim newstream As Stream = myrequest.GetRequestStream()
> > Dim myWriter As New StreamWriter(myrequest.GetRequestStream())
>
> > 'Send the data.
> > newstream.Write(data, 0, data.Length)
> > newstream.Close()
>
> > 'obtenim el Token
> > Dim objresponse As HttpWebResponse = myrequest.GetResponse
> > Dim sr As StreamReader = New
> > StreamReader(objresponse.GetResponseStream)
> > Dim resultat As String = Server.UrlDecode(sr.ReadToEnd)
>
> > Dim pos As Integer = InStr(resultat, "Auth=")
> > resultat = resultat.Substring(pos + 4)
> > sr.Close()
> > Return resultat
>
> > End Function
>
> > '---------------
> > 'SEND XML POST DATA
> > '---------------
>
> > Questions:
> > GoogleLogin auth=asdasd
> > or
> > GoogleLogin=aasdasd
> > or
> > auth=aassd
> > -----------------------------------------
>
> > Protected Sub bt_enviar_Click(ByVal sender As Object, ByVal e As
> > System.EventArgs) Handles bt_enviar.Click
>
> > Dim webrequest As HttpWebRequest =
> > HttpWebRequest.Create("https://www.google.com/a/feeds/facilcar.com/user/2.0")
> > webrequest.Method = "POST"
> > webrequest.ContentType = "application/atom+xml"
>
> > 'webrequest.Headers.Add(Net.HttpRequestHeader.Authorization,
> > "GoogleLogin
> > auth=DQAAAIMAAAA9wi_1qL9_vpNUDcg3ictwOcWqtcxoxgac6GUqtKK1wW_pvYJCgOOQb1zmRsYOuPwd6A3UcW0Kj1Z-8_ClFLMBJjCKsrnI_Q3GsbS68o9oDVq7mqztFTfFY5GU-
> > woJANndTXX6Z0SD2Hxl-
> > LNQpWkYqiuYKUJhuJpj550brqkUowFC07b0BrMtGAjf31kLm7k")
> > webrequest.Headers.Add(Net.HttpRequestHeader.Authorization,
> > "Authorization:GoogleLogin auth=" & GetToken())
>
> > Dim reader As StreamReader = New StreamReader(Server.MapPath("xml/
> > GrupSerhs.xml"))
> > Dim ret As String = reader.ReadToEnd
> > reader.Close()
>
> > Dim writer As StreamWriter = New
> > StreamWriter(webrequest.GetRequestStream())
> > writer.WriteLine(ret)
> > writer.Close()
>
> > Dim rsp As WebResponse = Nothing
> > Try
> > rsp = webrequest.GetResponse()
> > Me.lbl_resultat.Text = rsp.GetResponseStream.ToString
> > rsp.Close()
> > Catch ex As Exception
> > Me.lbl_resultat.Text = Err.Description & " (number=" & Err.Number &
> > ")"
> > End Try
>
> > End Sub
>
> > Thank you very much
> > Sergi Doutres
>
> > On May 15, 7:46 am, "Anirudh (Google)" <[EMAIL PROTECTED]> wrote:
>
> > > Hi Sergi,
>
> > > I tried using your code and could successfully authenticate hosted
> > > accounts.
> > > Could you please share some more details of the error you are
> > > receiving from the authentication service?
>
> > > You could try to get some more details on the error by probably
> > > handling the exceptions around the 'GetResponse' call.
>
> > > Dim objresponse As HttpWebResponse = Nothing
> > > Try
> > > objresponse = myrequest.GetResponse
>
> > > Catch webEx As WebException
> > > MsgBox(webEx.Message)
>
> > > Catch ex As Exception
> > > MsgBox(ex.Message)
>
> > > -Anirudh
>
> > > On May 13, 9:18 pm, Sergi Doutres <[EMAIL PROTECTED]> wrote:
>
> > > > Dim mail As String = "email"
> > > > Dim pwd As String = "pwd"
> > > > Dim encoding As ASCIIEncoding = New ASCIIEncoding
> > > > Dim postdata As String = ""
> > > > postdata = postdata & "accountType=HOSTED"
> > > > postdata = postdata & "&Email=" & Server.UrlEncode(mail)
> > > > postdata = postdata & "&Passwd=" & Server.UrlEncode(pwd)
> > > > postdata = postdata & "&service=apps"
> > > > Dim data As Byte() = encoding.GetBytes(postdata)
>
> > > > Dim myrequest As HttpWebRequest =
> > > > HttpWebRequest.Create("https://www.google.com/accounts/ClientLogin")
> > > > myrequest.Method = "POST"
> > > > myrequest.ContentType = "application/x-www-form-urlencoded"
> > > > myrequest.ContentLength = data.Length
> > > > Dim newstream As Stream = myrequest.GetRequestStream()
> > > > Dim myWriter As New StreamWriter(myrequest.GetRequestStream())
>
> > > > Try
> > > > myWriter.Write(postdata)
> > > > Catch ex As Exception
> > > > Response.Write(Err.Description)
> > > > Finally
> > > > myWriter.Close()
> > > > End Try
>
> > > > Dim objresponse As HttpWebResponse = myrequest.GetResponse
> > > > Dim sr As StreamReader = New
> > > > StreamReader(objresponse.GetResponseStream)
> > > > Dim resultat As String = Server.UrlDecode(sr.ReadToEnd)
>
> > > > Dim pos As Integer = InStr(resultat, "Auth=")
> > > > resultat = resultat.Substring(pos + 4)
> > > > sr.Close()
>
> > > > return (resultat)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Apps APIs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/google-apps-apis?hl=en
-~----------~----~----~----~------~----~------~--~---