elGringo Posted December 13, 2016 Posted December 13, 2016 Faced with uploading to keep2share through their API. They request through CURL Api here https://github.com/keep2share/api I tried to use Indy but it works partly From API "All request parameters must be encoded to JSON and sent using the POST method All methods return operation status (success, fail) and additional data in JSON" Ok they say we need to get auth_token for all other operations. I do it like this function TForm1.GetAuthtoken:string; var JSONObject:TJSONObject; ServerAnswer: string; JsonString: string; ss:TStringStream; i: Integer; begin JSONObject:=TJSONObject.Create; JSONObject.AddPair( (TJSONPair.Create('username','panteleevstas@gmail.com' )) ); JSONObject.AddPair( (TJSONPair.Create('password','SLwA63' )) ); JsonString:=JSONObject.ToString; ss:=TStringStream.Create(JsonString); ServerAnswer:=idHTTP.Post('http://keep2share.cc/api/v2/login', ss); Memo.Lines.Add(ServerAnswer); JSONObjectAfter:=TJSONObject.ParseJSONValue(ServerAnswer) as TJSONObject; Result:=JSONObjectAfter.Pairs[2].JsonValue.ToString;; Result.Substring(1,Result.Length-1); Memo.Lines.Add(Result); FreeAndNil(JSONObject); end; I succsesfully get auth_token Then i try to test some function and get ERROR 403 in sppite of i use the same method as above which works procedure TForm1.bTestClick(Sender: TObject); var JSONObject:TJSONObject; ServerAnswer: string; JsonString: string; ss:TStringStream; begin // JSONObject:=TJSONObject.Create; JSONObject.AddPair( (TJSONPair.Create('auth_token',GetAuthtoken )) ); JsonString:=JSONObject.ToString; ss:=TStringStream.Create(JsonString); ServerAnswer:=idHTTP.Post('http://keep2share.cc/api/v2/test', ss); Memo.Lines.Add(ServerAnswer); FreeAndNil(JSONObject); end; Maybe for CURL some special lib? Did anyone faced? Quote
rasaliad Posted December 30, 2016 Posted December 30, 2016 Hi, Here some helps with curl, but sorry is in spanish, maybe google translate can help. http://delphiaccess.com/foros/index.php/topic/10397-uso-de-tcurl-para-enviar-comando-a-parsecom/?p=82648 I hope this can give you some idea or help Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.