Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3 Image] [p]imgur search errors out
### Type:

- [ ] Suggestion
- [x] Bug

### Brief description of the problem
`[p]imgur search` produces an error
### Expected behavior
It should give links to images
### Actual behavior
`Error in command 'imgur search'. Check your console or logs for details.`
### Steps to reproduce

1. do `[p]imgur search cats`
2. get error

Traceback:

```py
Exception in command 'imgur search'
Traceback (most recent call last):
  File "/home/palm/redv3/lib/python3.5/site-packages/discord/ext/commands/core.py", line 62, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "/home/palm/redv3/lib/python3.5/site-packages/redbot/cogs/image/image.py", line 47, in imgur_search
    data = await search_get.json()
  File "/home/palm/redv3/lib/python3.5/site-packages/aiohttp/client_reqrep.py", line 730, in json
    headers=self.headers)
aiohttp.client_exceptions.ClientResponseError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8'
```


Discussion:

Resolving patch:
diff --git a/redbot/cogs/image/image.py b/redbot/cogs/image/image.py
--- a/redbot/cogs/image/image.py
+++ b/redbot/cogs/image/image.py
@@ -28,7 +28,6 @@ def __unload(self):
         self.session.close()
 
     @commands.group(name="imgur")
-    @commands.guild_only()
     async def _imgur(self, ctx):
         """Retrieves pictures from imgur
 
@@ -40,10 +39,16 @@ async def _imgur(self, ctx):
     @_imgur.command(name="search")
     async def imgur_search(self, ctx, *, term: str):
         """Searches Imgur for the specified term and returns up to 3 results"""
-        url = self.imgur_base_url + "time/all/0"
+        url = self.imgur_base_url + "gallery/search/time/all/0"
         params = {"q": term}
-        headers = {"Authorization": "Client-ID {}".format(await self.settings.imgur_client_id())}
-        async with self.session.get(url, headers=headers, data=params) as search_get:
+        imgur_client_id = await self.settings.imgur_client_id()
+        if not imgur_client_id:
+            await ctx.send(
+                _("A client ID has not been set! Please set one with {}").format(
+                    "`{}imgurcreds`".format(ctx.prefix)))
+            return
+        headers = {"Authorization": "Client-ID {}".format(imgur_client_id)}
+        async with self.session.get(url, headers=headers, params=params) as search_get:
             data = await search_get.json()
 
         if data["success"]:
@@ -81,9 +86,16 @@ async def imgur_subreddit(self, ctx, subreddit: str, sort_type: str="top", windo
         elif sort_type == "top":
             sort = "top"
 
+        imgur_client_id = await self.settings.imgur_client_id()
+        if not imgur_client_id:
+            await ctx.send(
+                _("A client ID has not been set! Please set one with {}").format(
+                    "`{}imgurcreds`".format(ctx.prefix)))
+            return
+
         links = []
-        headers = {"Authorization": "Client-ID {}".format(await self.settings.imgur_client_id())}
-        url = self.imgur_base_url + "r/{}/{}/{}/0".format(subreddit, sort, window)
+        headers = {"Authorization": "Client-ID {}".format(imgur_client_id)}
+        url = self.imgur_base_url + "gallery/r/{}/{}/{}/0".format(subreddit, sort, window)
 
         async with self.session.get(url, headers=headers) as sub_get:
             data = await sub_get.json()
@@ -111,6 +123,7 @@ async def imgurcreds(self, ctx, imgur_client_id: str):
         You can get these by visiting https://api.imgur.com/oauth2/addclient
         and filling out the form. Enter a name for the application, select
         'Anonymous usage without user authorization' for the auth type,
+        set the authorization callback url to 'https://localhost'
         leave the app website blank, enter a valid email address, and
         enter a description. Check the box for the captcha, then click Next.
         Your client ID will be on the page that loads"""


Test patch: