Subscribe to Subscribers

Resources » Code Snippets » AdSense APIs

Get error code from Google AdSense API calls


Posted Date:     Category: AdSense APIs    
Author: Member Level: Gold    Points: 10



Google AdSense APIs allow AdSense members to programmatically interact with AdSense accounts. However, when there is any exception in any AdSense API calls, it throws an Exception and the error code published by Google is wrapped somewhere deep inside the SOAP Exception. The following code snippet shows how to parse the SoapException class and retrieve the Google error code from it.

This function accepts the exception raised by Google AdSense API calls and returns the error code from the SoapException. If there is no valid error code, then it returns -1.


Public Shared Function GetErrorCode(ByVal ex As Exception) As Short
Dim errorCode As Short = -1

If (ex.GetType().FullName = "System.Web.Services.Protocols.SoapException") Then
Dim sx As System.Web.Services.Protocols.SoapException = ex

If (Not sx.Detail Is Nothing AndAlso Not String.IsNullOrEmpty(sx.Detail.InnerXml)) Then
Dim message As String = sx.Detail.InnerXml

message = "" + message + "" ' The XML message in the exception is not a valid XML. It does not have a ROOT node.

Dim doc As New Xml.XmlDocument
doc.LoadXml(message)

If (doc.GetElementsByTagName("ns1:code").Count > 0 AndAlso Not doc.GetElementsByTagName("ns1:code")(0).FirstChild Is Nothing) Then
Short.TryParse(doc.GetElementsByTagName("ns1:code")(0).FirstChild.Value, errorCode)
End If
End If
End If

Return errorCode
End Function





Did you like this resource? Share it with your friends and show your love!


Responses to "Get error code from Google AdSense API calls"
Author: Gaurav Arora    03 Aug 2008Member Level: Gold   Points : 1
Hi!

Its a good one, but I have tried the same, there is no response, Could you please tell the way to test it?



Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Get website URL of a AdSense publisher account
    Previous Resource: To write to a Excel file cell by cell and row by row basis.
    Return to Resources
    Post New Resource
    Category: AdSense APIs


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2013 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.