X OAuth2Configuration for MT4
FREE
Pubblicato:
15 novembre 2023
Versione attuale:
1.0
Non hai trovato un robot adatto?
Ordina il tuo
su Freelance
Vai alla sezione Freelance
Ordina il tuo
su Freelance
Come acquistare un Robot di Trading o un indicatore
Esegui il tuo EA
hosting virtuale
hosting virtuale
Prova un indicatore/robot di trading prima di acquistarlo
Vuoi guadagnare nel Market?
Come presentare un prodotto per venderlo con successo
Ti stai perdendo delle opportunità di trading:
- App di trading gratuite
- Oltre 8.000 segnali per il copy trading
- Notizie economiche per esplorare i mercati finanziari
Registrazione
Accedi
Accetti la politica del sito e le condizioni d’uso
Se non hai un account, registrati

Using the X_OAuth2Configuration script
Configure TweetHelper settings
utilizing Twitter API v2 OAuth 2.0 with PKCE.
instructions (1.00.1122)
Kagen.jp(加減)
Some of the images used in this instruction manual may not be up to date.
This procedure manual is current as of November 2023.
It is subject to change in the future.
---------------------------------------------------------------------------
Introduction
This document describes how to set up TweetHelper for "Twitter API v2 OAuth 2.0 with PKCE".
This section describes how to set up your TweetHelper environment.
Sign up for TwitterDeveloper and create a Twitter Developer account.
If you have not yet created an account, please refer to the official procedure to create an account.
Frequently asked questions about developer accounts and access
“https://developer.twitter.com/en/support/twitter-api/developer-account1”
Script for MetaTrader configuration
Make "X_OAuth2Configuration" ready to run in MetaTrader.---------------------------------------------------------------------------
1. Check your developer account settings
Twitter Developers > "Settings" > "User authentication settings"
“https://developer.twitter.com/en/portal/dashboard”
For the "Type of App" field, select "Web App, Automated App or Bot"
It is recommended that the "Callback URI / Redirect URL" in the App info be set to “http://localhost/”
This setting is used in "Step 1: Construct an Authorize URL" in "Twitter API v2 OAuth 2.0 with PKCE"
Twitter Developers > "Keys and tokens" > "OAuth 2.0 Client ID and Client Secret"
Issue the following two values and note the values down somewhere.
OAuth 2.0 Client ID
OAuth 2.0 Client Secret
2. Official "Twitter API v2 OAuth 2.0 with PKCE"
Follow the official Doc "How to connect to endpoints using OAuth 2.0 Authorization Code Flow with PKCE”
“https://developer.twitter.com/en/docs/authentication/oauth-2-0/user-access-token”
Step 0: Working with confidential clients
"OAuth 2.0 Client ID" and "OAuth 2.0 Client Secret" values, concatenate them with a single colon (":"), and then encode the resulting string in Base64. Please write down the obtained values.
Here is an example using Windows PowerShell commands
Let ${CLIENT_ID} be the OAuth 2.0 Client ID and ${CLIENT_SECRET} be the OAuth 2.0 Client Secret.
[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('${CLIENT_ID}:${CLIENT_SECRET}'))Example:
${CLIENT_ID} ID_001
${CLIENT_SECRET} AAAA
[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('ID_001:AAAA'))
Use your favorite tool other than PowerShell to get the string ('${CLIENT_ID}:${CLIENT_SECRET }') in Base64 encoding and make a note of it.
Execute "X_OAuth2Configuration" script (access token acquisition script)
MetaTrader preferences (add to WebRequest URL list)
“https://api.twitter.com”
---------------------------------------------------------------------------------------
Launch "X_OAuth2Configuration
Execute the script "X_OAuth2Configuration" to enter the input configuration state.
This is because the acquisition of the access token must be done within 30 seconds after executing step 2 of "Procedures for connecting using OAuth2.0".
Client ID : OAuth 2.0 Client ID
Auth Basic base64 : String for authentication with Base64 encoding
Response Code : auth_code to be obtained in Step 2 of "Connection Procedure Using OAuth2.0
Callback URI : “Callback URI / Redirect URL" set in AppInfo
--------------------------------------------------------------------------------
Steps to connect using OAuth 2.0
Step 1: Construct an Authorize URL
Authorize URL Template
https://twitter.com/i/oauth2/authorize?response_type=code&client_id=${CLIENT_ID}&redirect_uri=${Callback URI / Redirect URL}&scope=tweet.read%20users.read%20tweet.write&state=state&code_challenge=challenge&code_challenge_method=plain${CLIENT_ID} is OAuth 2.0 Client ID
${Callback URI / Redirect URL} is "Callback URI / Redirect URL" set in AppInfo
Example
${CLIENT_ID} is ID_001
${Callback URI / Redirect URL} is ”http://localhost/”
https://twitter.com/i/oauth2/authorize?response_type=code&client_id=ID_001&redirect_uri=http://localhost/&scope=tweet.read%20users.read%20tweet.write&state=state&code_challenge=challenge&code_challenge_method=plainStep 2: GET oauth2/authorize
Have the user authenticate, and upon successful authentication, send a request containing an auth_code parameter in the redirect_uri.
1. Log in to X with the account you wish to post with in a web browser.
2. Open another tab and paste the Authorize URL.
3. Have the user authenticate.
4. get the auth_code from the URL of the redirected page. "auth_code" of "&code=auth_code".
Example:
http://localhost/?state=state&code=ABCDEFG
Copy "ABCDEFG"
Step 3: POST oauth2/token - Access Token
Step 4: Connect to the APIs
Step 5: POST oauth2/token - refresh token
Go back to the "X_OAuth2Configuration" that was in the input state, paste "auth_code" in the "Response Code" field, and press the "OK" button.
Access Token acquisition must be performed within 30 seconds after Step 2 is executed
If the data cannot be obtained, perform it again from "Step 2: GET oauth2/authorize".
"X_OAuth2Configuration" will post a message to the authenticated account when the access token is successfully obtained.
[TweetHelper]
OAuth2 Configuration success
HELPER NO.1
At the same time, it makes the configuration persistent in case the token expires.
TweetHelper will automatically request a re-issue of the token just before or after the token expires based on this configuration.
Notice:
To authenticate with multiple X accounts, change the HelperNo to get an Access Token.
The default is HelperNo.1.
Trial version is fixed to HelperNo.1.
End of Comment
How to Link Posts with Code
[Image]
In the diagram, there are three charts open on MetaTrader:
Chart 1: Two indicators installed
Chart 2: One indicator installed
Chart 3: EA (TweetHelper) installed
Indicators on Charts 1 and 2: Send the desired message to TweetHelper
EA (TweetHelper) on Chart 3: Sequentially posts messages sent from the indicators
This is an example where messages are being checked on Twitter on a smartphone.
Instructions for Indicators on Charts 1 and 2
[Key Points]
1.Include the header file
#include <WizTweetBridge.mqh>2.Initial processing
Execute the initTweetBridge() method only once. In indicators or EAs, it is recommended to execute it in the OnInit() event handler.
The argument is the TweetHelper number (usually Helper No.1).
3.Check for the existence of TweetHelper
Before requesting a post, execute the isTweetHelperExist() method to check the existence of TweetHelper.
4.Check for completion of X (Twitter) authentication
Execute the isTweetHelperReady() method to check for completion of X (Twitter) authentication.
5.Request to post the message
Execute the passTweetHelper() method to request the posting of a message.
That's all. TweetHelper will then post the message.
Here's a sample script for using TweetHelper:
[Header File:] WizTweetBridge.mqh[Source Code:] helperTest.mq4, helperTest.mq5
Preparation
Usage
4. Double-click on [helperTest] or drag and drop it onto any chart.
[Code]
How to Link Posts with Code
[Image]
In the diagram, there are three charts open on MetaTrader:
Chart 1: Two indicators installed
Chart 2: One indicator installed
Chart 3: EA (TweetHelper) installed
Indicators on Charts 1 and 2: Send the desired message to TweetHelper
EA (TweetHelper) on Chart 3: Sequentially posts messages sent from the indicators
This is an example where messages are being checked on Twitter on a smartphone.
Instructions for Indicators on Charts 1 and 2