Sunday, June 26, 2022
HomeiOS Developmentios - Swift Methodology for acquiring AdMob API earnings report data

ios – Swift Methodology for acquiring AdMob API earnings report data


I have been having hassle retrieving my AdMob earnings report, and regardless of rigorously studying the AdMob API Doc on this hyperlink, I hold failing.

Solely the primary and second steps had been profitable in acquiring AdMob data.

  1. Step one was to log in with my Google Account, which was profitable.
  2. The second step, I used to be capable of efficiently receive AdMob Pub ID and Entry Token.
  3. The third step ought to have been to acquire my AdMob Incomes Report, nevertheless it saved failing. I spent every week researching on Google Docs, YouTube, and Stack Overflow with no success. That is the place I am having hassle.

I imagine there is a matter with OAuth2 or one thing, or presumably a problem with CURL. Right here is the code that’s inflicting CURL to fail.

func adMob_gettingReport(pid: String, token: String) {
    guard let url = URL(string: "https://admob.googleapis.com/v1/accounts/(pid)/mediationReport:generate") else { return }
    let reportData = "--data @- << EOF {"report_spec": {"date_range": {"start_date": {"12 months": 2020, "month": 4, "day": 1}, "end_date": {"12 months": 2020, "month": 4, "day": 1} },"dimensions": ["AD_SOURCE", "AD_UNIT", "PLATFORM"], "metrics": ["ESTIMATED_EARNINGS"]}} EOF"
    do {
        attempt CURL(#"curl -X POST "#(url)" -H "Authorization: Bearer #(token)" -H "Content material-Kind: software/json" #(reportData)"#).run { information, response, error in
            if let error = error { print("Error passed off (error)"); return }
            if let response = response as? HTTPURLResponse {
                if response.statusCode != 200 {
                    print("Error: (response)")
                } else {
                    if let information = information {
                        print("Getting AdMob Profitable")
                    }
                }
            }
        }
    } catch { print("Failed.") }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments