#pragma compile(Icon, C:\Program Files\AutoIt3\Icons\dropbox.ico) #include #include #include #include #include DirCreate(@desktopdir & "\Dropbox authenticator") ;fileinstall("C:\Users\jcampbell\Desktop\AutoIT\tokens.txt", @desktopdir & "\Dropbox authenticator\tokens.txt") ;fileinstall("C:\Users\jcampbell\Desktop\AutoIT\url.txt", @desktopdir & "\Dropbox authenticator\url.txt") Msgbox(0,"Welcome", "This was created to make getting your oauth_token and secret easier. When you first run this program it will create an empty folder on your desktop (please leave it as it needs to be on the desktop). As your progress though the program text files will be created as they are needed. make sure not to click ok on the messagebox without reading as it is vitial each step be complete before going onto the next.") gettoken() func gettoken() Global $App_Key = inputbox("App key", "Please enter your app key in the input box provided") Global $App_Secret = inputbox("App secret", "Please enter your app secret in the input box provided") Local $obj = ObjCreate("WinHttp.WinHttpRequest.5.1") local $time=currenttime() local $Random = Random(0,32767,1) ; using my fucntion _FindNetwork I can determine whether or not I need to set a proxy. This is so the user doesn't have to do anything and is all automated. ;if _FindNetwork() = "xavier" Then $obj.SetProxy(2, "proxy.school:3128") ;$obj.SetTimeouts(30000,60000,30000,400000) ;wait a max of 6.6 minutes for request to timeout $sUrl = ("https://api.dropbox.com/1/oauth/request_token"&'?oauth_consumer_key='&$App_Key&"&oauth_signature_method=PLAINTEXT&oauth_signature="&$App_secret&"%26"&"&oauth_timestamp="&$time&"&oauth_nonce="&$RANDOM) $obj.Open("POST", $sURL , False) $obj.Send($sUrl) local $status = $obj.Status local $Recieved = $obj.ResponseText local $FindError = FindError($status) If $obj.Status <> 200 Then $FindError = FindError($status) message($FindError) else ;message($obj.ResponseText) message($Recieved) $secret = GetSecret($Recieved) ;message("secret" & " "&$secret) $token = GetToken1($Recieved) ;message("token" & " "&$token) authorize($secret, $token) ;pause(100) local $url = "https://www.dropbox.com/1/oauth/authorize"&"?oauth_consumer_key="&$App_Key&"&oauth_token="&$token&"&oauth_signature="&$App_Secret&"&"&$secret&"&oauth_signature_method=PLAINTEXT" local $url1 = fileopen(@desktopdir & "\Dropbox authenticator\url.txt",2) filewrite($url1, "Url is" & " " & $url) fileclose($url1) MsgBox(0, "Instructions", "Go to the url.txt file in the dropbox authenticator folder, copy and paste the url into your browser and click the ok button when you have accepted authorization") AccessToken($secret, $token) endif endfunc func Accesstoken($secret, $token) Local $obj = ObjCreate("WinHttp.WinHttpRequest.5.1") local $time = currenttime() local $Random = Random(0,32767,1) ;message("App key" & " " & $App_Key) message($token) local $url = "https://api.dropbox.com/1/oauth/access_token"&"?oauth_consumer_key="&$App_Key&"&oauth_token="&$token&"&oauth_signature_method=PLAINTEXT&oauth_signature="&$App_Secret&"%26"&$secret&"&oauth_timestamp="&$time&"&oauth_nonce="&$Random ;message("url" & " " & $url) ;$size = stringlen($token) $obj.Open("POST", $url , False) ;$obj.SetResponseHeaders("content-length", $size) ;$obj.SetRequestHeader("User-Agent", "User-Agent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0") $obj.send($url) local $Recieved = $obj.ResponseText If $obj.Status <> 200 Then message($obj.status) message($obj.ResponseText) MsgBox(0, "Error", "Unable to retrieve your Oauth_token and secret at this time") else ;iniwrite(@scriptdir & "/ ;message($Recieved) ;$oauth_token_secret = GetSecret1($Recieved) ;$oauth_token = GetOauth($Recieved) msgbox(0, "Success", "Go to the dropbox authenticator folder, open tokens.txt and the last line has your most recent Oauth_token and secret") local $sFile = fileopen(@desktopdir & "\Dropbox authenticator\tokens.txt",1) filewrite($sFile, $Recieved) fileclose($sFile) endif endfunc func GetOauth($data) local $array = _StringBetween($data, "oauth_token=","&") return $array[0] endfunc func GetSecret1($data) local $array = _StringBetween($data, "oauth_token_secret=", "&") return $array[0] endfunc func authorize($token_secret, $access_token) local $time=currenttime() local $Random = Random(0,32767,1) local $url = "https://www.dropbox.com/1/oauth/authorize"&"?oauth_consumer_key="&$App_Key&"&oauth_token="&$access_token&"&oauth_signature="&$App_Secret&"&"&$token_secret&"&oauth_signature_method=PLAINTEXT"&"&oauth_timestamp="&$time&"&oauth_nonce="&$RANDOM local $Random = Random(0,32767,1) message("url is " & " "&$url) Local $obj = ObjCreate("WinHttp.WinHttpRequest.5.1") $obj.Open("GET", $url , False) ;if _FindNetwork() = "xavier" Then $obj.SetProxy(2, "proxy.school:3128") ;message($url) local $size = stringlen($url) $obj.SetResponseHeaders("content-length", $size) $obj.SetRequestHeader("User-Agent", "User-Agent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0") $obj.Send($url) local $status = $obj.Status local $Recieved = $obj.ResponseText If $obj.Status <> 200 Then local $FindError = FindError($status) message($FindError) else message($obj.Status) endif endfunc func GetToken1($str) Local $pie = _StringBetween($str, "oauth_token=","") ; gets the text starting from oauth_token to the end of the file if $pie = 1 then message("error") else return $pie[0] endif endfunc func GetSecret($str) local $pie = _StringBetween($str,"oauth_token_secret=","&") if $pie = 1 then message(@error) else ;message("pie is" & " " &$pie[0]) return $pie[0] endif endfunc Func currenttime() return _DateDiff('s', "1970/01/01 00:00:00", _NowCalc()) EndFunc func FindError($apple) switch 1 case $apple = 400 return "Bad input parameter" case $apple = 401 return "Bad or expired token." case $apple = 403 return "Bad OAuth request (wrong consumer key, bad nonce, expired timestamp...). " case $apple = 404 return "File or folder not found at the specified path." case $apple = 405 return "Request method not expected (generally should be GET or POST)." case $apple = 429 return "Your app is making too many requests and is being rate limited" case $apple = 503 return "OAuth 1.0 app is being rate limited. " case $apple = 507 return "User is over Dropbox storage quota." case $apple = 5&"xx" return "server error" endswitch endfunc Func message($pea) ; consolewrite writes whatever value you want to the stdout stream ConsoleWrite(@Mday&"/"&@mon&" "&@hour&":"&@min&":"&@sec&" --> " & $pea & @CRLF) endfunc