Hỏicái này lấy trên imgur

5 bài đăng
Tags:
29.06.2016 / 05:49
ga_bong
Bài đăng: 519
Member
♔ Lovemoon.wap.mu ♔

nó đây! chả hiểu gì luôn -_-

PHP
  1. property Client_ID : "XXXXXXX"
  2. property Client_Secret : "XXXXXXX"
  3. property refresh_token : "XXXXXXX"
  4.  
  5. -- Supported file types
  6. property fileTypes : {"jpeg", "jpg", "gif", "png", "apng", "tiff", "bmp", "pdf", "xcf"}
  7.  
  8. -- If true, this will enclose the URL in a [img][/img] tag
  9. property img_tag : true
  10.  
  11. property listOfLinks : {}
  12.  
  13. on run
  14. -- Verify the selected file is a supported file type
  15. tell application "Finder"
  16. set userSelect to (selection as alias list)
  17. if (count of userSelect) < 1 then
  18. tell me to badChoice()
  19. else if name extension of first item of userSelect is not in fileTypes then
  20. tell me to badChoice()
  21. end if
  22. end tell
  23.  
  24. --Request new token
  25. set a to do shell script "curl -X POST -F client_id=" & Client_ID & " -F client_secret=" & Client_Secret & " -F grant_type=refresh_token -F refresh_token=" & refresh_token & " https://api.imgur.com/oauth2/token"
  26. set {TID, text item delimiters} to {text item delimiters, {"\"access_token\":\"", "\",\"expires_in"}}
  27. set new_token to text item 2 of a
  28. set text item delimiters to TID
  29. -- Upload the file
  30. repeat with i from 1 to number of items of the userSelect
  31. set selectedItem to item i of the userSelect
  32. set theFile to quoted form of POSIX path of selectedItem
  33. set imgurUpload to do shell script "curl -X POST -H 'Authorization: Bearer " & new_token & "' -F image=@" & theFile & " https://api.imgur.com/3/upload "
  34.  
  35. -- Copy the URL into your clipboard
  36. set {TID, text item delimiters} to {text item delimiters, {"http:\\/\\/i.imgur.com\\/", "\"},\"success\":true,\"status\":200}"}}
  37. if img_tag then
  38. copy "[img]http://i.imgur.com/" & text item 2 of imgurUpload & "[/img]" & "\n" to the end of listOfLinks
  39. else
  40. copy "http://i.imgur.com/" & text item 2 of imgurUpload & "\n" to the end of listOfLinks
  41. end if
  42.  
  43. -- Reset delimiters
  44. set text item delimiters to TID
  45. end repeat
  46. set the clipboard to listOfLinks as string
  47. set listOfLinks to {}
  48. end run
  49.  
  50. on badChoice()
  51. using terms from application "Finder"
  52. tell me
  53. activate
  54. display alert "Please select ONE supported file and try again." message "Allowed file types: JPEG, JPG, GIF, PNG, APNG, TIFF, BMP, PDF, XCF (GIMP). " & return & return & "Please note that the TIFF, BMP, PDF and XCF formats will be converted to PNG on upload." buttons "OK" cancel button "OK"
  55. end tell
  56. end using terms from
  57. end badChoice
29.06.2016 / 06:43
b0ysh0ckhn
Bài đăng: 1146
Member
Nguyễn Minh Phương

kiếm đâu code ngộ thế

29.06.2016 / 07:48
ga_bong
Bài đăng: 519
Member
♔ Lovemoon.wap.mu ♔

sinhvien.it :)

29.06.2016 / 08:49
MrKen
Bài đăng: 2653
Trùm!
Vẫn là A N H

code dành cho máy MAC nhé

29.06.2016 / 09:10
ga_bong
Bài đăng: 519
Member
♔ Lovemoon.wap.mu ♔

OMG :(