googleapis / google-api-php-client

A PHP client library for accessing Google APIs
http://googleapis.github.io/google-api-php-client/
Apache License 2.0
9.29k stars 3.52k forks source link

v2.8 client fails on parsing duration from FLASH Creative #1308

Closed peterviergutz closed 7 years ago

peterviergutz commented 7 years ago

Hey,

while upgrading from v2.7 to v2.8 I've noticed that parsing of the API response in this code

//...

$creativeSearchCriteria = [
    'maxResults' => 1000,
    'sortField' => 'ID',
    'sortOrder' => 'DESCENDING',
    'campaignId' => $dfaCampaignId,
    'pageToken' => $pageToken,
];

$result = $this->dfaReportingService->creatives->listCreatives($this->dfaProfileId, $creativeSearchCriteria);

//...

fails with error

Class name must be a valid object or a string {
    "file": "\/vendor\/google\/apiclient\/src\/Google\/Model.php",
    "line": 113,
}

when trying to parse on this object from the API response:

array:20 [
  "id" => "---REMOVED---"
  "assetIdentifier" => array:2 [
    "type" => "FLASH"
    "name" => "---REMOVED---"
  ]
  "sslCompliant" => true
  "size" => array:4 [
    "kind" => "dfareporting#size"
    "width" => 300
    "height" => 250
    "iab" => false
  ]
  "fileSize" => "45853"
  "actionScript3" => false
  "displayType" => "ASSET_DISPLAY_TYPE_INPAGE"
  "artworkType" => "ARTWORK_TYPE_HTML5"
  "zIndex" => 1000000
  "transparency" => false
  "pushdown" => false
  "pushdownDuration" => 0.0
  "verticallyLocked" => false
  "horizontallyLocked" => false
  "customStartTimeValue" => 0
  "duration" => 0
  "hideFlashObjects" => false
  "hideSelectionBoxes" => false
  "role" => "PRIMARY"
  "backupImageExit" => array:8 [
    "artworkLabel" => "exit"
    "id" => "---REMOVED---"
    "artworkType" => "ARTWORK_TYPE_HTML5"
    "advertiserCustomEventName" => "exit"
    "targetType" => "TARGET_BLANK"
    "advertiserCustomEventType" => "ADVERTISER_EVENT_EXIT"
    "exitUrl" => "---REMOVED---"
    "advertiserCustomEventId" => "---REMOVED---"
  ]
]

It seems to think that key duration is sort of a complex object in Google_Model::mapTypes and fails to find a proper $propertyClass in line 113. v2.7 works fine.

We're using this set of google libs:

✗ composer show | grep google
google/apiclient                          v2.2.0             Client library for Google APIs
google/apiclient-services                 v0.27              Client library for Google APIs
google/auth                               v1.0.1             Google Auth Library for PHP
googleads/googleads-php-lib               13.1.0             Google Ads APIs Client Library for PHP (AdWords and DFP)

Am I missing something?

bshaffer commented 7 years ago

Hmm interesting, it could be an issue with the Discovery API. @saicheems

bshaffer commented 7 years ago

Also, I am unsure what you mean by v2.8, as you can see in your comment we are dealing with v2.2 and v0.27.

peterviergutz commented 7 years ago

I am upgrading from v2.7 to v2.8 of the Dfareporting service, which is included in the google/apiclient-services - sorry, missed that in the report.

bshaffer commented 7 years ago

Makes sense! Thank you.

bshaffer commented 7 years ago

I found the issue. The problem is durationType is an actual API field, whereas the library looks for the prepending of Type to any complex variable (see the discovery API).

I've submitted PR #1310 to fix this. Please run your application with the fix and let me know if it works. You can do that by changing your composer.json via the composer command:

composer require "google/apiclient:dev-issue-1308 as v2.2.0"
peterviergutz commented 7 years ago

I can confirm your PR solves the issue - thanks a lot for the quick fix! 🚀