Krishnaveni N
Krishnaveni N

Reputation: 21

Google Blogger API is returning 403 error

I am developing an iOS app to show the public posts from my blog/website. As suggested in Google Developer Guidelines, Created the iOS Public API key under “Google Developers Console” and included GTL Client library and required sources in my project. Also enabled the blogger V3 API in Google Developer Console.

When I execute the query to get the blog using blogID reports following error:

An Error Occurred! Error Domain=com.google.GTLJSONRPCErrorDomain Code=403 "(Insufficient Permission)" UserInfo={error=Insufficient Permission, NSLocalizedFailureReason=(Insufficient Permission), GTLStructuredError=GTLErrorObject 0x7fe743766030: {message:"Insufficient Permission" data:[1] code:403}}

Code Snippest:

let bloggerService : GTLServiceBlogger =  GTLServiceBlogger()

override func viewDidLoad() {
    super.viewDidLoad()
    self.bloggerService.authorizer  = GTMOAuth2ViewControllerTouch.authForGoogleFromKeychainForName(kKeychainItemName as String, clientID: kClientID, clientSecret: nil)
    
    bloggerService.APIKey = kAPIKey;
    let query : GTLQueryBlogger = GTLQueryBlogger.queryForBlogsGetWithBlogId(kBlogID)

    self.bloggerService.executeQuery(query, completionHandler:  { (ticket, blogList , error) -> Void in
        if error == nil {
            print("Blog list = \(blogList)")
        } else {
            print("An Error Occurred! \(error)")
            self.showAlert(“Error”, message: "Sorry, an error occurred!")
        }
        
    })

If I comment out the authorisation code(self.bloggerService.authorizer = GTMOAuth2ViewControllerTouch.authForGoogleFromKeychainForName(kKeychainItemName as String, clientID: kClientID, clientSecret: nil)), the error will be different:

An Error Occurred! Error Domain=com.google.GTLJSONRPCErrorDomain Code=403 "(There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referrer should be allowed.)" UserInfo={error=There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referrer should be allowed., NSLocalizedFailureReason=(There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referrer should be allowed.), GTLStructuredError=GTLErrorObject 0x7fe41945b170: {message:"There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referrer should be allowed." data:[1] code:403}}

Can somebody please help me to resolve this issue?

Note: Actually when I run this HTTP request in Google API Explorer(“https://developers.google.com/apis-explorer/#p/blogger/v3/blogger.blogs.get”), it returns the JSON response.

Upvotes: 2

Views: 420

Answers (0)

Related Questions