Help! Can't get access token

Created at 27 Mar 2017, 00:41
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
YC

ycomp

Joined 16.10.2013

Help! Can't get access token
27 Mar 2017, 00:41


I followed the instructions here:

https://connect.spotware.com/docs/tutorials/lesson-2-get-trading-data

and on other pages.

I tried unsuccesfully with both chrome and IE

What happens is I get the page with the allow access / no thanks buttons

But after clicking allow access, it immediately redirects me back to the page I came from.

There is no token string shown on the screen. 

How can I create some tokens?

thanks.


@ycomp
Replies

mindbreaker
27 Mar 2017, 19:42

You need catch $_GET['code'] from redirect url script and change the code to token:

if your redirect url is: https://domain.com/app-redirect-uri.php

 

<?php
error_reporting('E_ALL');
// App client id
$cID = 'xxx_xxxxxxxxx';
// App secret 
$cSecret = 'xxxxxxxxxxxx';
// App redirect uri
$cUri = 'https://domain.com/connect/redirect.php';

if (isset($_GET['code'])) {

	// Secure input data
	$cReceive = htmlentities($_GET['code'], ENT_QUOTES, 'utf-8');
	//$cReceive = preg_replace("/[^a-zA-Z0-9_-]/", "", $_GET['code']);

	$cGetUserAccessToken = 'https://connect.spotware.com/apps/token?grant_type=authorization_code&code='.$cReceive.'&redirect_uri='.$cUri.'&client_id='.$cID.'&client_secret='.$cSecret;
	// get response
	$res = file_get_contents($cGetUserAccessToken);	

	if ($res != false) {
		// save to file
		file_put_contents('token-'.time().'.secret', $res);		
		$tokens = json_decode($res, true);
		print_r($tokens);
	}

}else{
	echo '<h1 style="color: #000; width: 100%; text-align: center">[ERROR_INPUT_DATA]</h1>';
}

 


@mindbreaker

mindbreaker
28 Mar 2017, 17:04

Here how start with connect https://connect.spotware.com/docs/available-resources/playground


@mindbreaker

mindbreaker
28 Mar 2017, 19:42

My youtube video:

Spotware Connect Api how to get access token and get data from cTrader server from url (connect api, cTID, link accounts to cTID).

https://youtu.be/SRoKIpp-Gog


@mindbreaker

ycomp
29 Mar 2017, 07:27

RE:

mindbreaker said:

My youtube video:

Spotware Connect Api how to get access token and get data from cTrader server from url (connect api, cTID, link accounts to cTID).

https://youtu.be/SRoKIpp-Gog

thanks, the video was useful 

I have a problem now that I have Trading and Accounts API access via the sandbox test account (connect@spotware.com), however I can't get a list of symbols (empty) nor trade "EURUSD" with a market order ("CH_SYMBOL_NOT_FOUND")

Do you know how I can get a demo account to try that has symbols available?

I tried to make my own Application and cTraderID but I have even less success, I think maybe because the Application says "submitted" next to it - so maybe it is not active yet ?So with those tokens I can't connect and authorize

Do you know when I authorize the trading API, how often is that required? 


@ycomp

mindbreaker
29 Mar 2017, 09:09

RE: RE:

ycomp said:

mindbreaker said:

My youtube video:

Spotware Connect Api how to get access token and get data from cTrader server from url (connect api, cTID, link accounts to cTID).

https://youtu.be/SRoKIpp-Gog

thanks, the video was useful 

I have a problem now that I have Trading and Accounts API access via the sandbox test account (connect@spotware.com), however I can't get a list of symbols (empty) nor trade "EURUSD" with a market order ("CH_SYMBOL_NOT_FOUND")

Do you know how I can get a demo account to try that has symbols available?

I tried to make my own Application and cTraderID but I have even less success, I think maybe because the Application says "submitted" next to it - so maybe it is not active yet ?So with those tokens I can't connect and authorize

Do you know when I authorize the trading API, how often is that required? 

Don't test on sandbox (create new email on google, create new cTID connect new demo account from fxpro.co.uk or fro other broker and test whitout sandbox).

I dont know but when i try on sandbox it does not work, i try many times on sandbox but same results (does not work)

get all account symbols

https://api.spotware.com/connect/tradingaccounts/{id}/symbols?access_token=XXXXXXXXXX

 


@mindbreaker

mindbreaker
29 Mar 2017, 09:11

RE: RE: RE:

here page with all actions:

https://connect.spotware.com/docs/api-reference/accounts-api


@mindbreaker

ycomp
29 Mar 2017, 11:05

RE: RE: RE:

mindbreaker said:

ycomp said:

mindbreaker said:

My youtube video:

Spotware Connect Api how to get access token and get data from cTrader server from url (connect api, cTID, link accounts to cTID).

https://youtu.be/SRoKIpp-Gog

thanks, the video was useful 

I have a problem now that I have Trading and Accounts API access via the sandbox test account (connect@spotware.com), however I can't get a list of symbols (empty) nor trade "EURUSD" with a market order ("CH_SYMBOL_NOT_FOUND")

Do you know how I can get a demo account to try that has symbols available?

I tried to make my own Application and cTraderID but I have even less success, I think maybe because the Application says "submitted" next to it - so maybe it is not active yet ?So with those tokens I can't connect and authorize

Do you know when I authorize the trading API, how often is that required? 

Don't test on sandbox (create new email on google, create new cTID connect new demo account from fxpro.co.uk or fro other broker and test whitout sandbox).

I dont know but when i try on sandbox it does not work, i try many times on sandbox but same results (does not work)

get all account symbols

https://api.spotware.com/connect/tradingaccounts/{id}/symbols?access_token=XXXXXXXXXX

 

thanks, now I got the symbols to work this way (eliminating sandbox urls and going to the  connect (not sandbox-connect) cTrader ID site)


@ycomp

mindbreaker
29 Mar 2017, 13:33

Second video ho get tokens from clients accounts and how refresh token: https://www.youtube.com/watch?v=wHxURyh7PS0


@mindbreaker

NFZ-Trader
05 Aug 2023, 20:11

I'm following this topic, but I'm having the same difficulty, but when I click on the pages the links don't work, and the videos are off the air  

I'm trying to use the formula below but it doesn't work

https://openapi.ctrader.com/apps/auth?client_id={your_app_client_id}&redirect_uri={redirect_uri}&scope=accounts
 


@NFZ-Trader

PanagiotisChar
07 Aug 2023, 11:53

Hi there,

You will not receive something on your screen. You will receive a code in your URL which can be used to retrieve the token. Check the web example on GitHub, it might be helpful

https://github.com/spotware/OpenAPI.Net/tree/master/samples/ASP.NET.Sample

Aieden Technologies

Need help? Join us on Telegram


@PanagiotisChar