MDL-69006 repository_flickr: flickr authentication fails
authorBas Brands <bas@moodle.com>
Wed, 10 Jun 2020 13:08:41 +0000 (15:08 +0200)
committerBas Brands <bas@moodle.com>
Wed, 10 Jun 2020 13:46:13 +0000 (15:46 +0200)
- Flickr does not like useragents including the word "Bot"

lib/flickrclient.php
lib/oauthlib.php

index 7d37551..de57c32 100644 (file)
@@ -60,12 +60,16 @@ class flickr_client extends oauth_helper {
      * @param moodle_url|string $callbackurl
      */
     public function __construct($consumerkey, $consumersecret, $callbackurl = '') {
+        global $CFG;
+        $version = moodle_major_version();
+        $useragent = "MoodleSite/$version (+{$CFG->wwwroot})";
 
         parent::__construct([
             'api_root' => self::OAUTH_ROOT,
             'oauth_consumer_key' => $consumerkey,
             'oauth_consumer_secret' => $consumersecret,
             'oauth_callback' => $callbackurl,
+            'http_options' => ['CURLOPT_USERAGENT' => $useragent]
         ]);
     }
 
index a20d2d9..30c192f 100644 (file)
@@ -108,7 +108,11 @@ class oauth_helper {
             $this->access_token_secret = $args['access_token_secret'];
         }
         $this->http = new curl(array('debug'=>false));
-        $this->http_options = array();
+        if (!empty($args['http_options'])) {
+            $this->http_options = $args['http_options'];
+        } else {
+            $this->http_options = array();
+        }
     }
 
     /**