diff --git a/java/pom.xml b/java/pom.xml index 269f07d..f1c89a5 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -60,25 +60,11 @@ org.apache.maven.plugins maven-compiler-plugin - 3.3 + 3.8.0 - javac-with-errorprone - true 7 7 - - - org.codehaus.plexus - plexus-compiler-javac-errorprone - 2.7 - - - com.google.errorprone - error_prone_core - 2.1.2 - - org.codehaus.mojo diff --git a/php/ContentSession.php b/php/ContentSession.php index db0c8a3..8893ba1 100644 --- a/php/ContentSession.php +++ b/php/ContentSession.php @@ -299,8 +299,29 @@ public function getHome() { return rtrim($home, '\\/'); } + private function getToken(Google_Client $client) { + $client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob'); + $client->setScopes('https://www.googleapis.com/auth/content'); + $client->setAccessType('offline'); // So that we get a refresh token + + printf("Visit the following URL and log in:\n\n\t%s\n\n", + $client->createAuthUrl()); + print ('Then type the resulting code here: '); + $code = trim(fgets(STDIN)); + $client->authenticate($code); + + return $client->getAccessToken(); + } + protected function cacheToken(Google_Client $client) { - throw new Exception('This example currently only supports the service account flow..'); + print (str_repeat('*', 40) . "\n"); + print ("Your token was missing or invalid, fetching a new one\n"); + $token = $this->getToken($client); + $tokenFile = join(DIRECTORY_SEPARATOR, + [$this->configDir, self::OAUTH_TOKEN_FILE_NAME]); + file_put_contents($tokenFile, json_encode($token, JSON_PRETTY_PRINT)); + printf("Token saved to %s\n", $tokenFile); + print (str_repeat('*', 40) . "\n"); } /** diff --git a/python/shopping/content/reports/get_product_performance.py b/python/shopping/content/reports/get_product_performance.py deleted file mode 100644 index 63676b3..0000000 --- a/python/shopping/content/reports/get_product_performance.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2022 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -"""Gets performance data of all products on the specified account.""" - -import json -import sys - -from shopping.content import common - - -def main(argv): - # Authenticate and construct service. - service, config, _ = common.init(argv, __doc__) - merchant_id = config['merchantId'] - - # You can use relative date ranges or custom date ranges. This example - # uses a relative date range. - date_range = 'LAST_30_DAYS' - - # Choose the programs for which you want to get performance metrics. - programs = "('FREE_PRODUCT_LISTING','SHOPPING_ADS')" - - query = f""" - SELECT - segments.title, - segments.offer_id, - metrics.impressions, - metrics.clicks - FROM MerchantPerformanceView - WHERE segments.date DURING {date_range} - AND segments.program IN {programs} - ORDER BY metrics.clicks DESC - """ - - req_body = { - 'query': query - } - - # Build request - request = service.reports().search( - merchantId=merchant_id, - body=req_body) - - # Send request - result = request.execute() - - # Check to ensure the result is not an empty object - if bool(result): - results = result['results'] - product_data = [] - - # Extract product data from the request results - for row in results: - data = {} - data['offer_id'] = row['segments'].get('offerId') - data['title'] = row['segments'].get('title') - data['impressions'] = row['metrics'].get('impressions') - data['clicks'] = row['metrics'].get('clicks') - product_data.append(data) - - # Convert product_data to a JSON string - json_product_data = json.dumps(product_data) - print('product_data:') - print(json_product_data) - else: - print('Your search query returned no results.') - -if __name__ == '__main__': - main(sys.argv) \ No newline at end of file