last day (30 days later) » 

12:01 AM
@MB1965 Are you there now?
@MB1965 Excuse me.But this question haunt me long time.
 
@yode yeah, glad to try to help
 
I'm sorry for disturb.
 
No problem. If you're based in Hong Kong, China, or using Tor you will probably need to get an authorization token before you can add images.
You will also need an account (if you don't have it)
 
And actually I have read this page many times before I ask that question
 
Right. It suggests that you don't need a token.
But the discrepancy makes sense if you're covered under help.imgur.com/hc/en-us/articles/…
 
12:07 AM
But my English is a threshold to understand that fully
 
Ah yeah. Let me see if I can figure out how to format an auth token call.
 
But how to get token?
Oh,I have to say one thing,that I can access Imgur by my browser.
 
So you have a client id
 
Yes,I have
 
Right I'm guessing the issue is the API call
And then you encode that in an HTTPRequest
Let me knock up a template that should work
 
12:09 AM
So do you think this also is a reason that I cannot use SETool?
 
What is SETool?
 
A tool to send image to Imgur
I thought you know that.
 
Nah, I'm just familiar with all this API stuff
 
If necessay,I can give you my account
 
Shouldn't be. Try this
$username = "";
$password = "";
$clientid = "93d5e807261cc90";
HTTPRequest[<|
"Scheme" -> "https",
"Domain" -> "api.imgur.com",
"Path" -> {"oauth2", "authorize"},
"Username" -> $username,
"Password" -> $password,
"Query" -> {
"client_id" -> $clientid,
"response_type" -> "pin",
"state" -> "application"
}
|>] // Import
Where you fill in your username and password
Without the username or password it wants you to go to a website
Oh wait
One sec
$username = "";
$password = "";
$clientid = "93d5e807261cc90";
HTTPRequest[<|
"Scheme" -> "https",
"Domain" -> "api.imgur.com",
"Path" -> {"oauth2", "authorize"},
"Query" -> {
"client_id" -> $clientid,
"response_type" -> "pin",
"state" -> "application"
}
|>,
<|
"Username" -> $username,
"Password" -> $password
|>] // Import
That's what you want. The parameters are in a second association. The url definition is the first.
 
12:17 AM
it give me a output like
 
Blech
That means it wants you to log into a website.
Here's another option:
go here: "https://api.imgur.com/oauth2/authorize?client_id=93d5e807261cc90&\
response_type=token&state=application"
That's the same without mathematica's formatting
You'll get an API token
And then record that
We'll use that for all your future calls.
 
I get a address
https://api.imgur.com/oauth2/justtest?state=application#access_token=77b77c681851b9a3cc394e8eb843b195f2b3359c&expires_in=2419200&token_type=bearer&refresh_token=d764edbcfdf88c9772caa63bdf02809b367e465f&account_username=zyd199012&account_id=41276274
 
Great!
Yes that's what we needed
That access_token is the token we'll use for your calls now
 
Why I get another address when I open that address
It is this now
https://api.imgur.com/oauth2/justtest?state=application#access_token=dc84d1e42e98bd1a84283777064318d2dc5292e4&expires_in=2419200&token_type=bearer&refresh_token=f0a870baf6579b7ff8e92ea48529eccbb2000bd6&account_username=zyd199012&account_id=41276274
 
I think that's the refresh token.
Being activated
We just want the most recent access_token
 
12:26 AM
Oh,I see now
 
$accesstoken = "dc84d1e42e98bd1a84283777064318d2dc5292e4";
$refreshtoken = "f0a870baf6579b7ff8e92ea48529eccbb2000bd6";
$accountusername = "zyd199012";
$accountid = "41276274";

$fname = FileNameJoin@{$TemporaryDirectory, "img.png"};
$file = Export[$fname, Plot[Sin[x], {x, 0, 2 Pi}], "PNG"];
$req =
HTTPRequest["https://api.imgur.com/3/image",
<|Method -> "Post",
"Headers" -> {
"Authorization" ->
"Bearer " <> $accesstoken,
"Accept" -> "application/json"},
"Body" -> {"image" -> File[$file], "type" -> "file"}|>];
Try that
Oh
Actually the $TemporaryDirectory should work for you too
I got this: {"status" -> 200, "success" -> True,
"data" -> {"vote" -> Null, "bandwidth" -> 0,
"link" -> "http://i.imgur.com/0Uk6yQ8.png", "title" -> Null,
"type" -> "image/png", "id" -> "0Uk6yQ8", "account_id" -> 41276274,
"datetime" -> 1489537598, "account_url" -> Null,
"animated" -> False, "tags" -> {}, "description" -> Null,
"width" -> 360, "deletehash" -> "4ng4AOFOEw9O8X6", "height" -> 214,
"size" -> 9895, "views" -> 0, "favorite" -> False, "name" -> "",
"section" -> Null, "nsfw" -> Null, "is_ad" -> False,
 
But I get this still
 
Hmm...
Let me read more on the end points
From the docs
That's certainly a functional access token
 
Thank in advance.I have to say this is a sad thing to me,which trap me very long time.
 
Yeah
That certainly seems like a pain
So there's also this: api.imgur.com/errorhandling#500
Which is odd
As you can access imgur from a web browser, right?
 
12:32 AM
Yes,it is
And I can upload image from here
 
Okay
Which means the service is functional, overall.
GOod
 
 
When did you get that 500 error earlier?
I'm trying to figure out if there's just something wrong with imgur...
 
It's seem this approximately is after 2016/3
 
Hm
Let's see if it will ever work (their docs suggest that a 500 error is an oddity, but I'm not so convinced)
$fname = FileNameJoin@{$TemporaryDirectory, "img.png"};
$file = Export[$fname, Plot[Sin[x], {x, 0, 2 Pi}], "PNG"];
$req =
HTTPRequest["https://api.imgur.com/3/image",
<|
Method -> "Post",
"Headers" -> {
"Authorization" ->
"Bearer " <> $accesstoken,
"Accept" -> "application/json"},
"Body" -> {"image" -> File[$file], "type" -> "file"}
|>];
n = 1;
NestWhile[Import[$req] &,
Import[$req], (n++ < 10 && Lookup[#, "status"] &)]
Oh wait
Forgot to test "status"...
$fname = FileNameJoin@{$TemporaryDirectory, "img.png"};
$file = Export[$fname, Plot[Sin[x], {x, 0, 2 Pi}], "PNG"];
$req =
HTTPRequest["https://api.imgur.com/3/image",
<|
Method -> "Post",
"Headers" -> {
"Authorization" ->
"Bearer " <> $accesstoken,
"Accept" -> "application/json"},
"Body" -> {"image" -> File[$file], "type" -> "file"}
|>];
n = 1;
NestWhile[Import[$req] &,
Import[$req], (n++ < 10 && Lookup[#, "status"] == 500 &)]
Try that one instead
 
12:45 AM
little confusion,why your variable name start with $?
 
It's a constant
 
And it give still
{status->500,success->False,data->{error->Imgur is temporarily over capacity. Please try again later.}}
 
I tend to do that for permanent constants.
Okay cool.
That means after 10 requests it's still outputting that.
 
I don't think that "cool".:)
Aha
 
Which I would think suggests there's an API malfunction in your region? Do you get any web search results for the related?
Perhaps "Okay interesting"
Is a better way to put it
 
12:47 AM
wait a sec,
I'm running my another computer to test
 
1:04 AM
@MB1965 I'm sorry maybe I will give you the response about test result
 
@yode take however long you need
 
@MB1965 Maybe a say news,my another old computer can get the normally result
 
Interesting
Do you use Tor?
Because per that page Tor users can't use the API.
 
What meaning of Tor?
 
Nevermind then
It's a browser that hides your identity online
Very thoroughly.
@yode What are the two computers you're using?
 
1:13 AM
Do you think this a question can be solved?
 
I bet it can.
I'm just wondering what the differences of the HTTP requests your old vs new computer send are.
 
I'm not very understand "What are the two computers you're using?"
 
Sorry, you said you have a different computer that it works for?
Is that not what you meant by this: "Maybe a say news,my another old computer can get the normally result"?
 
This is a laptop which cannot run that code normally,and that old desktop can
 
Okay
I'll see what I can find
So I think the thing to do now is to ask the imgur people, who can apparently be contacted at api@imgur.com
Tell them that 1) you've gone through all the registration / authentication steps
2) you can get the calls to work on your old desktop
3) you can't get the api to work on your laptop
Since you can get it to work on your old desktop it's fixable.
 
1:30 AM
Think a lot. :)
 
The only thing I can think of now is that maybe there's something funky with the SSL between your new laptop and the imgur API but I find that enormously unlikely
But they'll be able to help you.
 
I will email them now
 
@yode if you want all the code I was working with you can find it here: wolframcloud.com/objects/…
 
@MB1965 This is good method to share mathematica code. :)
 
That's what the cloud is for
 

  last day (30 days later) »