Paypal Express Payment Execution - asp.net

I'm developing in vb.net and as of right now I am not using any API's to receive transaction details I have only been using IPN and PDT variables to get my details however I began to notice that, when using Paypal Sandbox to test, after I go through the process of check out, I do receive all the variables of the details but in my test account, there are no transactions shown.
Do I need to be using the REST API in order to actually approve and execute the payment for the transaction in order to complete a transaction? I had assumed that the entire transaction had been completed successful since I was getting all of the details back but now that I noticed there aren't any transactions showing in my account I'm not so sure whats going on?
Here is the code I have been using to view transaction details
Dim authToken As String = "c37yqZU7UdVWesSoipRHFOwB3fFLv1CfOKWz10hqp0ULz6dYKrlCNuxp9d0"
Dim txToken As String = Request.QueryString("tx")
txToken = "2F816064M1280054A" '"6AX4295820157674V" '"5PD1935338742763G" ' '"70Y83841KE749971T" '"74C31896AA9005743""2RY90202U2008611C" '"0F824628H9566062P" '"5ET57654YS955312K" '
Dim strRequest As String = "cmd=_notify-synch&tx=" & txToken & "&at=" & authToken
'Dim Payerinfo As New PayerInfo
'Dim trans As New Transaction
'Dim tra As New PayPal.PayPalAPIInterfaceService.Model.GetTransactionDetailsReq
'post back to either sandbox or live
Dim strSandbox As String = "https://www.sandbox.paypal.com/cgi-bin/webscr"
Dim strLive As String = "https://www.paypal.com/cgi-bin/webscr"
Dim req As HttpWebRequest = CType(WebRequest.Create(strSandbox), HttpWebRequest)
'req.Headers = valHeader
'Set values for the request back
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
req.ContentLength = strRequest.Length
'Send the request to PayPal and get the response
Dim streamOut As StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
streamOut.Write(strRequest)
streamOut.Close()
Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
Dim strResponse As String = streamIn.ReadToEnd()
streamIn.Close()
If Not String.IsNullOrEmpty(strResponse) Then
Dim results As New Dictionary(Of String, String)
Dim reader As New StringReader(strResponse)
Dim line As String = reader.ReadLine()
If line = "SUCCESS" Then
'FormView1.Visible = False
While True
Dim aLine As String
aLine = reader.ReadLine
If aLine IsNot Nothing Then
Dim strArr() As String
strArr = aLine.Split("=")
results.Add(strArr(0), strArr(1))
Else
Exit While
End If
End While
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'when code below is uncommented remove these two end if's below
Response.Write("<li> " + results("payer_id") + "</li>")
Response.Write("<li> " + results("txn_id") + "</li>")
' Displays all the keys for results, helps to see what the keys are named for writing to text file
For Each kvp As KeyValuePair(Of String, String) In results
Dim v1 As String = kvp.Key
Dim v2 As String = kvp.Value
Response.Write(v1.ToString _
+ ": " + v2 + "<br /> ")
Next
End If

Related

Send Excel file to Browser Asp.net

I have been breaking my head for the last two days and can't get this to work. I have a report, which I am exporting to Excel and saving on the server file directory. That part works perfectly, I can see the file, and open it, all good. The issue relies on when I try to send it to the browser for download from the server. It does not download anything, I do see the Response Header with all the info on the browser but nothing happens.
Here's one of my many tries
Private Sub dxgvPOAll_ToolbarItemClick(source As Object, e As ASPxGridViewToolbarItemClickEventArgs) Handles dxgvPOAll.ToolbarItemClick
Select Case e.Item.Name
Case "ExportAll"
Using report As DevExpress.XtraReports.UI.XtraReport = New POs_Dashboard_Report()
Using ms As New System.IO.MemoryStream()
report.Name = "Backorder Tickets"
report.ExportOptions.PrintPreview.SaveMode = DevExpress.XtraPrinting.SaveMode.UsingSaveFileDialog
Dim xlsxExportOptions As New DevExpress.XtraPrinting.XlsxExportOptions() With {.ExportMode = DevExpress.XtraPrinting.XlsxExportMode.SingleFile, .ShowGridLines = True, .FitToPrintedPageHeight = True}
Dim folderPath As String = "~/Account/TemporaryFiles/" & Utilities.RetrieveEmployeeNumber() & "/" & Guid.NewGuid.ToString & "/"
Dim serverPath As String = Server.MapPath(folderPath)
Dim xlsxExportFilePath As String = serverPath & report.Name & ".xlsx"
Dim folderInf As New DirectoryInfo(serverPath)
If Not folderInf.Exists Then folderInf.Create()
report.ExportToXlsx(xlsxExportFilePath, xlsxExportOptions)
Try
Dim objRequest As FileWebRequest = CType(WebRequest.Create(xlsxExportFilePath), FileWebRequest)
Dim objResponse As FileWebResponse = CType(objRequest.GetResponse(), FileWebResponse)
Dim bufferSize As Integer = 1
Response.Clear()
Response.ClearHeaders()
Response.ClearContent()
Response.AppendHeader("Content-Disposition:", "attachment; filename=" & xlsxExportFilePath)
Response.AppendHeader("Content-Length", objResponse.ContentLength.ToString())
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Dim byteBuffer As Byte() = New Byte(bufferSize + 1 - 1) {}
Dim memStrm As MemoryStream = New MemoryStream(byteBuffer, True)
Dim strm As Stream = objRequest.GetResponse().GetResponseStream()
Dim bytes As Byte() = New Byte(bufferSize + 1 - 1) {}
While strm.Read(byteBuffer, 0, byteBuffer.Length) > 0
Response.BinaryWrite(memStrm.ToArray())
Response.Flush()
End While
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.SuppressContent = True
HttpContext.Current.ApplicationInstance.CompleteRequest()
Catch e1 As ThreadAbortException
Catch ex As Exception
End Try
End Using
End Using
End Select
End Sub
Here's what I see on the browser's Response-Header:

Converting HTML to PDF and attaching to email .NET

I am looking to use PDFSharp to convert a HTML page into a PDF. This then is attached into an email and sent all in one go.
So, I have a aspx page and vb code file in which gets called through a database SQL job.
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim ReqUrl As String, WorkflowID As String = String.Empty
Using con As New SqlConnection(GlobalVariables.ConStr)
Using com As New SqlCommand("EXEC App.GetWorkflowToSend", con)
con.Open()
Using dr = com.ExecuteReader
Try
While dr.Read
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
ReqUrl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + dr.Item("WorkflowLink")
WorkflowID = dr.Item("WorkflowID")
Dim r As String = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + dr.Item("WorkflowLink")
Dim p As String = Server.MapPath("~\Data\Files") + "\" + WorkflowID + ".pdf"
Dim t As Thread = New Thread(CType(
Function()
ConvertHTML(r, p)
SendMail(Nothing, EmailFrom, "email#address", "New PDF Generated " + WorkflowID, r + "<br/>" + p + "<br/>" + WorkflowID, EmailUser, EmailPass, EmailHost, EmailPort, EmailSSL, "", Nothing, p)
End Function, ThreadStart))
t.SetApartmentState(ApartmentState.STA)
t.Start()
Response.Write(r + "<br>")
Response.Write(p)
End While
Catch
SendMail(Nothing, EmailFrom, "email#address", "Error: " + Err.Description, WorkflowID, EmailUser, EmailPass, EmailHost, EmailPort, EmailSSL, "", Nothing)
End Try
End Using
End Using
End Using
End Sub
In the vb code I essentially call a database stored procedure. This returns some records.
For each of these records, I am currently using HttpContext.Current.Request.Url to make up a string which is essentially the the document url.
I also then declare and specify the location as a String of where I want the converted PDF to be stored.
Public Shared Function ConvertHTML(HTMLPage As String, FileName As String) As String
Dim pngfilename As String = Path.GetTempFileName()
Dim res As String = "" ' = ok
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
'Try
Using wb As System.Windows.Forms.WebBrowser = New System.Windows.Forms.WebBrowser
wb.ScrollBarsEnabled = False
wb.ScriptErrorsSuppressed = True
wb.Navigate(HTMLPage)
While Not (wb.ReadyState = WebBrowserReadyState.Complete)
Application.DoEvents()
End While
wb.Width = wb.Document.Body.ScrollRectangle.Width
wb.Height = wb.Document.Body.ScrollRectangle.Height
If wb.Height > 3000 Then
wb.Height = 3000
End If
' Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
Dim b As Bitmap = New System.Drawing.Bitmap(wb.Width, wb.Height)
Dim hr As Integer = b.HorizontalResolution
Dim vr As Integer = b.VerticalResolution
wb.DrawToBitmap(b, New Rectangle(0, 0, wb.Width, wb.Height))
wb.Dispose()
If File.Exists(pngfilename) Then
File.Delete(pngfilename)
End If
b.Save(pngfilename, Imaging.ImageFormat.Png)
b.Dispose()
Using doc As PdfSharp.Pdf.PdfDocument = New PdfSharp.Pdf.PdfDocument
Dim page As PdfSharp.Pdf.PdfPage = New PdfSharp.Pdf.PdfPage()
page.Width = PdfSharp.Drawing.XUnit.FromInch(wb.Width / hr)
page.Height = PdfSharp.Drawing.XUnit.FromInch(wb.Height / vr)
doc.Pages.Add(page)
Dim xgr As PdfSharp.Drawing.XGraphics = PdfSharp.Drawing.XGraphics.FromPdfPage(page)
Dim img As PdfSharp.Drawing.XImage = PdfSharp.Drawing.XImage.FromFile(pngfilename)
xgr.DrawImage(img, 0, 0)
doc.Save(FileName)
doc.Close()
img.Dispose()
xgr.Dispose()
End Using
End Using
Return res
End Function
I run the conversion function with these two strings and finally call a mailing function.
PDF Error
The problem I am having at the moment is the attached PDF I receive in the email doesn't contain the correct output and states 'Navigation to the webpage was cancelled'.
http://127.0.0.1/PDF/TTR/4
C:\inetpub\wwwroot\Prod\Data\Files\4.pdf
I also sent the two strings as output within the email and they look ok.
I'm sure there is something small missing whether that be in my conversion function or just in the main code file.

How can I programmatically cancel an outlook meeting with asp.net VB?

I can programmatically create a meeting request that is sent to the user through code and appears in Outlook mail where the user can accept the request and if accepted the appointment shows on their Outlook calendar. but am having trouble figuring out how to programmatically cancel the same event.
The below code is what I am using to send the meeting invitation. It works as should and sends the request to the recipient and they can accept or decline. If accepted the appointment goes on their calendar.
Dim smtpServer As String = ConfigurationManager.AppSettings("MailServer").ToString()
Dim credentials As New NetworkCredential(ConfigurationManager.AppSettings("SMTPUser").ToString(), ConfigurationManager.AppSettings("SMTPPassword").ToString())
Dim startTime1 As String = Convert.ToDateTime("10/30/2015 11:00 AM").ToString("yyyyMMddTHHmmss")
Dim endTime1 As String = Convert.ToDateTime("10/30/2015 01:00 PM").ToString("yyyyMMddTHHmmss")
Dim smtp As New SmtpClient(smtpServer)
smtp.Credentials = credentials
Dim msg As New MailMessage()
Dim emailFrom As String = ConfigurationManager.AppSettings("EmailFrom").ToString()
Dim emailTo As String = "jd#dom.com"
msg.From = New MailAddress(emailFrom, "Scheduling System")
msg.[To].Add(New MailAddress(emailTo))
msg.Subject = "JD"
Dim strBody As New StringBuilder()
strBody.AppendLine("Appointment Confirmation")
strBody.AppendLine("Subject: JD")
strBody.AppendLine("1599")
strBody.AppendLine("Location: Exam 1")
strBody.AppendLine("Date: 10/30/2015")
strBody.AppendLine("Time: 11:00AM - 1:00PM")
msg.Body = strBody.ToString()
Dim str As New StringBuilder()
str.AppendLine("BEGIN:VCALENDAR")
'PRODID: identifier for the product that created the Calendar object
str.AppendLine("PRODID:-//CARS//Outlook MIMEDIR//EN")
str.AppendLine("VERSION:2.0")
str.AppendLine("METHOD:REQUEST")
str.AppendLine("BEGIN:VEVENT")
str.AppendLine(String.Format("DTSTART:{0:yyyyMMddTHHmmss}", startTime1))
'TimeZoneInfo.ConvertTimeToUtc("BeginTime").ToString("yyyyMMddTHHmmssZ")));
str.AppendLine(String.Format("DTSTAMP:{0:yyyyMMddTHHmmss}", DateTime.Now))
str.AppendLine(String.Format("DTEND:{0:yyyyMMddTHHmmss}", endTime1))
'TimeZoneInfo.ConvertTimeToUtc("EndTime").ToString("yyyyMMddTHHmmssZ")));
str.AppendLine(String.Format("LOCATION:{0}", "Exam 1"))
' UID should be unique.
str.AppendLine(String.Format("UID:{0}", "jd101"))
str.AppendLine(String.Format("DESCRIPTION:{0}", msg.Body))
str.AppendLine(String.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", msg.Body))
str.AppendLine(String.Format("SUMMARY:{0}", msg.Subject))
str.AppendLine("STATUS:CONFIRMED")
str.AppendLine("BEGIN:VALARM")
str.AppendLine("TRIGGER:-PT15M")
str.AppendLine("ACTION:Accept")
str.AppendLine("DESCRIPTION:Reminder")
str.AppendLine("X-MICROSOFT-CDO-BUSYSTATUS:BUSY")
str.AppendLine("END:VALARM")
str.AppendLine("END:VEVENT")
str.AppendLine(String.Format("ORGANIZER:MAILTO:{0}", msg.From.Address))
str.AppendLine(String.Format("ATTENDEE;CN=""{0}"";RSVP=TRUE:mailto:{1}", msg.[To](0).DisplayName, msg.[To](0).Address))
str.AppendLine("END:VCALENDAR")
Dim ct As New System.Net.Mime.ContentType("text/calendar")
ct.Parameters.Add("method", "REQUEST")
ct.Parameters.Add("name", "meeting.ics")
Dim avCal As AlternateView = AlternateView.CreateAlternateViewFromString(str.ToString(), ct)
msg.AlternateViews.Add(avCal)
smtp.Send(msg)
The below code is what I have to CANCEL an existing meeting. It sends the notice out just like the above code does, but it does not cancel/delete/remove the meeting. Can someone point me in the right direction please. I would just like the event to be removed from the Outlook calendar when this part of the code is ran. Thanks for any help.
Dim smtpServer As String = ConfigurationManager.AppSettings("MailServer").ToString()
Dim credentials As New NetworkCredential(ConfigurationManager.AppSettings("SMTPUser").ToString(), ConfigurationManager.AppSettings("SMTPPassword").ToString())
Dim startTime1 As String = Convert.ToDateTime("10/30/2015 11:00 AM").ToString("yyyyMMddTHHmmss")
Dim endTime1 As String = Convert.ToDateTime("10/30/2015 01:00 PM").ToString("yyyyMMddTHHmmss")
Dim smtp As New SmtpClient(smtpServer)
smtp.Credentials = credentials
Dim msg As New MailMessage()
Dim emailFrom As String = ConfigurationManager.AppSettings("EmailFrom").ToString()
Dim emailTo As String = "jd#dom.com"
msg.From = New MailAddress(emailFrom, "Scheduling System")
msg.[To].Add(New MailAddress(emailTo))
msg.Subject = "JD"
Dim strBody As New StringBuilder()
strBody.AppendLine("Appointment Confirmation")
strBody.AppendLine("Subject: JD")
strBody.AppendLine("HRPO#: 1599")
strBody.AppendLine("Location: Exam 1")
strBody.AppendLine("Date: 10/30/2015")
strBody.AppendLine("Time: 11:00AM - 1:00PM")
msg.Body = strBody.ToString()
Dim str As New StringBuilder()
str.AppendLine("BEGIN:VCALENDAR")
'PRODID: identifier for the product that created the Calendar object
str.AppendLine("PRODID:-//CARS//Outlook MIMEDIR//EN")
str.AppendLine("VERSION:2.0")
str.AppendLine("METHOD:REQUEST")
str.AppendLine("BEGIN:VEVENT")
str.AppendLine(String.Format("DTSTART:{0:yyyyMMddTHHmmss}", startTime1))
'TimeZoneInfo.ConvertTimeToUtc("BeginTime").ToString("yyyyMMddTHHmmssZ")));
str.AppendLine(String.Format("DTSTAMP:{0:yyyyMMddTHHmmss}", DateTime.Now))
str.AppendLine(String.Format("DTEND:{0:yyyyMMddTHHmmss}", endTime1))
'TimeZoneInfo.ConvertTimeToUtc("EndTime").ToString("yyyyMMddTHHmmssZ")));
str.AppendLine(String.Format("LOCATION:{0}", "Exam 1"))
' UID should be unique.
str.AppendLine(String.Format("UID:{0}", "jd101"))
str.AppendLine(String.Format("DESCRIPTION:{0}", msg.Body))
str.AppendLine(String.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", msg.Body))
str.AppendLine(String.Format("SUMMARY:{0}", msg.Subject))
str.AppendLine("STATUS:CANCELLED")
str.AppendLine("BEGIN:VALARM")
str.AppendLine("TRIGGER:-PT15M")
str.AppendLine("ACTION:Accept")
str.AppendLine("DESCRIPTION:Reminder")
str.AppendLine("X-MICROSOFT-CDO-BUSYSTATUS:BUSY")
str.AppendLine("END:VALARM")
str.AppendLine("END:VEVENT")
str.AppendLine(String.Format("ORGANIZER:MAILTO:{0}", msg.From.Address))
str.AppendLine(String.Format("ATTENDEE;CN=""{0}"";RSVP=TRUE:mailto:{1}", msg.[To](0).DisplayName, msg.[To](0).Address))
str.AppendLine("END:VCALENDAR")
Dim ct As New System.Net.Mime.ContentType("text/calendar")
ct.Parameters.Add("method", "CANCEL")
ct.Parameters.Add("name", "meeting.ics")
Dim avCal As AlternateView = AlternateView.CreateAlternateViewFromString(str.ToString(), ct)
msg.AlternateViews.Add(avCal)
smtp.Send(msg)
ANSWERED
To cancel the meeting and have it removed from the outlook calendar you need to change the Method from "REQUEST" to "CANCEL" for the event that sends the cancellation request.
msg.Body = strBody.ToString()
Dim str As New StringBuilder()
str.AppendLine("BEGIN:VCALENDAR")
'PRODID: identifier for the product that created the Calendar object
str.AppendLine("PRODID:-//CARS//Outlook MIMEDIR//EN")
str.AppendLine("VERSION:2.0")
'''ORIGINAL-CHANGE TO CANCEL'''
'str.AppendLine("METHOD:REQUEST")
'''NEW - CHANGE TO CANCEL'''
str.AppendLine("METHOD:CANCEL")
'''Everything else remains the same. Will work and remove meeting from calendar.'''
Currently i am using this code to send meeting to outlook..
StringBuilder OutlookBody = new StringBuilder();
string textvs = #"BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN
VERSION:1.0
BEGIN:VEVENT
LOCATION:" + Location + #"
DTSTART:" + string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", start) + #"
DTEND:" + string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", end) + #"
DESCRIPTION;ENCODING=QUOTED-PRINTABLE:=
" + OutlookBody + #"=0D=0A
SUMMARY:" + AppoitmentName + #"
PRIORITY:3
END:VEVENT
END:VCALENDAR";
And it is working fine..
How can i use the same code to cancel / remove appointment from outlook.

Get Paypal Express cart Price right before checkout

I am using paypal express checkout and I'm trying to get the total value that is in the shopping cart when the user decides to checkout. My shipping rate is going to be based on the total price and although I have the shipping calculations filled out in my paypal account settings, the shipping cost is not showing up in the checkout screen. How would I grab the total shopping cart price right upon checkout so that I can add the shipping cost? What I have so far is only the values after the user has checked out and they are returned back to my website but at this point it is too late to add shipping.
Dim authToken As String = "sdf5414FdsfDFS5eEF52s336DFLLJUhhbuzek64"
Dim txToken As String = Request.QueryString("tx")
txToken = "4GGSES84eEWSS"
Dim strRequest As String = "cmd=_notify-synch&tx=" & txToken & "&at=" & authToken
'Dim Payerinfo As New PayerInfo
'Dim trans As New Transaction
'Dim tra As New PayPal.PayPalAPIInterfaceService.Model.GetTransactionDetailsReq
'post back to either sandbox or live
Dim strSandbox As String = "https://www.sandbox.paypal.com/cgi-bin/webscr"
Dim strLive As String = "https://www.paypal.com/cgi-bin/webscr"
Dim req As HttpWebRequest = CType(WebRequest.Create(strSandbox), HttpWebRequest)
'req.Headers = valHeader
'Set values for the request back
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
req.ContentLength = strRequest.Length
'Send the request to PayPal and get the response
Dim streamOut As StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
streamOut.Write(strRequest)
streamOut.Close()
Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
Dim strResponse As String = streamIn.ReadToEnd()
streamIn.Close()
If Not String.IsNullOrEmpty(strResponse) Then
Dim results As New Dictionary(Of String, String)
Dim reader As New StringReader(strResponse)
Dim line As String = reader.ReadLine()
If line = "SUCCESS" Then
'FormView1.Visible = False
While True
Dim aLine As String
aLine = reader.ReadLine
If aLine IsNot Nothing Then
Dim strArr() As String
strArr = aLine.Split("=")
results.Add(strArr(0), strArr(1))
Else
Exit While
End If
End While
' Displays all the keys for results, helps to see what the keys are named for writing to text file
For Each kvp As KeyValuePair(Of String, String) In results
Dim v1 As String = kvp.Key
Dim v2 As String = kvp.Value
Response.Write(v1.ToString _
+ ": " + v2 + "<br /> ")
Next
End If
I have also been trying to declare a session variable and add to it every time the add to cart button is clicked but I see a problem in this because I don't know how long the items will stay in the paypal cart and if the session variable session runs out of time and is cleared, they will then receive free shipping since the shipping amount clears out. Is their any way to make this work?
Protected Sub AddToCartBtn_Click(sender As Object, e As EventArgs)
Session("CartAmount")
Dim itemNumber As String = str2
Dim itemAmount As String = price
Dim currencyCode As String = "USD"
Dim addItem As Integer = 1
Dim ppHref As StringBuilder = New StringBuilder()
ppHref.Append("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_cart")
ppHref.Append("&business=" + business)
ppHref.Append("&item_name=" + itemName)
ppHref.Append("&item_number=" + itemNumber)
ppHref.Append("&amount=" + itemAmount)
ppHref.Append("&currency_code=" + currencyCode)
Session("CartAmount") = (cartTotal + Session("CartAmount"))
End Sub
You can pass shopping cart values in the provided variable from the following url reference,
https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/#id08A6HF080O3

Google contacts v3 integration with ASP.NET VB

I completed a google contacts integration and it worked until some time ago.
I started getting this error
The remote server returned an error: (400) Bad Request. at System.Net.HttpWebRequest.GetResponse()
at Google.GData.Client.OAuthBase.GetOAuth2AccessToken(OAuth2Parameters parameters, String requestBody) at Google.GData.Client.OAuthUtil.GetAccessToken(OAuth2Parameters parameters)
at Success.Page_Load(Object sender, EventArgs e)
and
Execution of request failed: https://www.google.com/m8/feeds/contacts/default/full at Google.GData.Client.GDataRequest.Execute()
at Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)
at Google.GData.Client.GDataGAuthRequest.Execute()
at Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince, String etag, Int64& contentLength)
at Google.GData.Client.Service.Query(FeedQuery feedQuery)
at Google.GData.Client.Feed1.get_AtomFeed()
at Google.GData.Client.Feed1.d__0.MoveNext()
at Success.PrintAllContacts(ContactsRequest cr)
Please what could be the problem.
Please find my codes below
Dim o2 As New OAuth2Parameters
o2.ClientId = ""
o2.ClientSecret = ""
o2.RedirectUri = "http://localhost:6498/Success"
o2.Scope = "https://www.googleapis.com/auth/contacts.readonly"
'o2.Scope = "https://www.google.com/m8/feeds"
o2.ApprovalPrompt = "force"
Dim iURL As String = OAuthUtil.CreateOAuth2AuthorizationUrl(o2)
Session("MailServer") = "Google"
Response.Redirect(iURL)
and on http://localhost:6498/Success
o2.AccessCode = Request.QueryString("Code") 'After the user has allowed contacts...bring to this page
OAuthUtil.GetAccessToken(o2)
Dim reqSettings As New RequestSettings("", "tobi.omitiran#gmail.com")
reqSettings.OAuth2Parameters = o2
reqSettings.
Dim contReq As New ContactsRequest(reqSettings)
Dim Contacts As Feed(Of Google.Contacts.Contact) = contReq.GetContacts()
Dim Name As String = Nothing
Dim iEmail As String = ""
Dim iPhone As String = Nothing
For Each objContact As Google.Contacts.Contact In Contacts.Entries
Dim iName As Name = objContact.Name
For Each emailId As EMail In objContact.Emails
iEmail = iEmail & emailId.Address.ToString() & ";"
Next
For Each Phone As PhoneNumber In objContact.Phonenumbers
iPhone = iPhone & Phone.Home.ToString() & "," & Phone.Work.ToString() & ","
Next
BLL.WriteLog(iName.FullName)
BLL.WriteLog(iEmail)
BLL.WriteLog(iPhone)
DL.Insert_Lead(iName.FullName, iEmail, iPhone, Session("iLeadInvite"))
Next

Resources