Catchable fatal error: Object of class Money could not be converted to string

82 views
Skip to first unread message

Shobhan Babu

unread,
Jun 25, 2015, 1:55:11 AM6/25/15
to adwor...@googlegroups.com

How to convert object of class money to rupees

I have the following code ,but  I am unable to print the AVG.CPC of the Keyword

I am using GetKeywordIdeas.php

function GetKeywordIdeasExample(AdWordsUser $user) {
  // Get the service, which loads the required classes.
  $targetingIdeaService =
      $user->GetService('TargetingIdeaService', ADWORDS_VERSION);

  // Create seed keyword.
  $keyword = 'mars cruise';

  // Create selector.
  $selector = new TargetingIdeaSelector();
  $selector->requestType = 'IDEAS';
  $selector->ideaType = 'KEYWORD';
  $selector->requestedAttributeTypes = array('KEYWORD_TEXT', 'SEARCH_VOLUME',
      'AVERAGE_CPC');

  // Create language search parameter (optional).
  // The ID can be found in the documentation:
  // Note: As of v201302, only a single language parameter is allowed.
  $languageParameter = new LanguageSearchParameter();
  $english = new Language();
  $english->id = 1000;
  $languageParameter->languages = array($english);

  // Create related to query search parameter.
  $relatedToQuerySearchParameter = new RelatedToQuerySearchParameter();
  $relatedToQuerySearchParameter->queries = array($keyword);
  $selector->searchParameters[] = $relatedToQuerySearchParameter;
  $selector->searchParameters[] = $languageParameter;

  // Set selector paging (required by this service).
  $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);

  do {
    // Make the get request.
    $page = $targetingIdeaService->get($selector);

    // Display results.
    if (isset($page->entries)) {
      foreach ($page->entries as $targetingIdea) {
        $data = MapUtils::GetMap($targetingIdea->data);
        $keyword = $data['KEYWORD_TEXT']->value;
        $search_volume = isset($data['SEARCH_VOLUME']->value)
            ? $data['SEARCH_VOLUME']->value : 0;
$avgCPC = isset($data['AVERAGE_CPC']->value)
            ? $data['AVERAGE_CPC']->value : 0;
     
       printf("Keyword idea with text '%s', category IDs (%d) and average "
            . "monthly search volume '%s' was found.\n",
            $keyword, $categoryIds, $avgCPC);
            
      }
    } else {
      print "No keywords ideas were found.\n";
    }

    // Advance the paging index.
    $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
  } while ($page->totalNumEntries > $selector->paging->startIndex);
}


output: Catchable fatal error: Object of class Money could not be converted to string

Josh Radcliff (AdWords API Team)

unread,
Jun 25, 2015, 10:47:27 AM6/25/15
to adwor...@googlegroups.com, sho...@multipliersolutions.in
Hi,

Money objects have a microAmount attribute that will contain the currency amount in micros. Please try calling $avgCPC->microAmount to get this value.

Cheers,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages