Google search console apis with visual basic net
Sabtu, 06 Januari 2018
Edit
As webmaster you may add yout site to google webmaster console manually.
But with google console search API you can do it automatically.
Google api end point is: PUT https://www.googleapis.com/webmasters/v3/sites/siteUrl
But when I use with rest API
like this: PUT https://www.googleapis.com/webmasters/v3/sites/siteUrl?access_token=myToken
google give Unauthorized
So I try wih authorization by .NET api library
Here is the code:
Dim webmasterScope() As String = New String() {WebmastersService.Scope.Webmasters}
Dim scopes As String() = webmasterScope
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(New ClientSecrets() With { _
.ClientId = yourAppClientID, _
.ClientSecret = yourAppClientSecret _
}, scopes, "user", CancellationToken.None).Result
Here is my code to Add site to google webmaster console:
Dim initializer As New BaseClientService.Initializer()
initializer.HttpClientInitializer = credential
initializer.ApplicationName = "VB.NET Webmaster Tools"
Dim service As WebmastersService = New WebmastersService(initializer)
service.Sites.Add(sUrlToAdd).Execute()
But with google console search API you can do it automatically.
Google api end point is: PUT https://www.googleapis.com/webmasters/v3/sites/siteUrl
But when I use with rest API
like this: PUT https://www.googleapis.com/webmasters/v3/sites/siteUrl?access_token=myToken
google give Unauthorized
So I try wih authorization by .NET api library
Here is the code:
Dim webmasterScope() As String = New String() {WebmastersService.Scope.Webmasters}
Dim scopes As String() = webmasterScope
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(New ClientSecrets() With { _
.ClientId = yourAppClientID, _
.ClientSecret = yourAppClientSecret _
}, scopes, "user", CancellationToken.None).Result
Here is my code to Add site to google webmaster console:
Dim initializer As New BaseClientService.Initializer()
initializer.HttpClientInitializer = credential
initializer.ApplicationName = "VB.NET Webmaster Tools"
Dim service As WebmastersService = New WebmastersService(initializer)
service.Sites.Add(sUrlToAdd).Execute()