This blog shows you how to use the Twitter ICS Connector that comes out of the box in Oracle Integration Cloud Service.
Obtain your Twitter Connector in ICS
In order to create a Twitter Connector you need to first go to Twitter developers portal and create an access token. For this:
- Login to the Twitter Developer portal at https://dev.twitter.com/
- ON the top right, click on My apps and follow the link to log in (sign up if you don’t have an account yet).
- Create your app by clicking on “Create New App”
-
Complete the information about your app and accept the Developer Agreement at the bottom:
Note: For the Callback URL, enter the OAuth 2.0 Authorized Redirect URL callback of your ICS domain. It is in the form of:
https://YOUR_SERVER:PORT/icsapis/agent/oauth/callback
- When done click on “Create your Twitter application“.
- Confirm that you get a successful creation message:
- Move to “Keys and Access Tokens” tab and at the bottom click on “Create my access token” to authorise this application to get access to the Twitter account.
- Make sure you get a successful result indicating that the application access tokens have been successfully generated.
Also, make sure that you can see them at the bottom of the page…
- Make sure the Access Level is set to Read and Write.
Note: In the Oracle documentation, it is indicated to upload Twitter’s public certificate into Oracle Integration Cloud Service, but I did not have to do it for my account. I leave you here the link in case you had to do it.
- Keep handy your security information as it will be required when creating the Twitter connector from within ICS. However, do not share this information, as it is confidential.
Create a Twitter Connection in ICS:
In this section, we are going to create a Twitter Connection that will simplify the integration
- Open ICS and go to Connections
- Click on Create New Connection
- Select Twitter connector
- Enter a sensible name and Description.
- Set the Connection Role to Invoke. Then click on Create
- Enter a Connection Administration Email if you want
- Click on “Configure Security“
- From your Twitter dev account, go inside the application created in the previous section and grab the respective information being required here:
- When done, click OK.
- Click on Save, Test and Save to complete the connection.
Create a REST connection in ICS
In this section, we are going to create a very simple REST connector that will allow us to integrate into Twitter via the Twitter connector that we just created earlier.
Note: This is a generic REST connector. If you have already completed the other blogs around how to build an integration to either Facebook, LinkedIn, Google Calendar, etc. Then potentially you can simply reuse that REST connector. If not, feel free to create one and enter a different name.
- Log into ICS and go to Connections.
- Click on “Create New Connection” – This time select REST adapter.
- Enter a name for your REST adapter. In my case, I’m calling it “s2viia-rest-conn”
- In this case, I just want it to trigger my post, so I select just Trigger.
- Enter a description if you want. Then click on Create
- Enter an email if you want.
- We are leaving the default Basic Authentication as the security mechanism.
- Click Save and then Test. Ensure you get a green 100% status. Click save again and “Exit Connection“
- Congratulations, you have created two connectors! One Twitter connector and one REST connector. In the next section, we are going to build an integration between them.
Post a message in your Twitter account using a REST API via ICS
In this section, we are going to create a very simple integration to Post a message to my Twitter account. We will expose this as a REST API using both connectors that we built previously, the Twitter and REST connectors respectively.
- Log into ICS if not already there
- Go to Integrations.
- Click on “Create New Integration”
- For now, let’s just create a simple mapping. Select “Basic Map Data“
- Enter a name for your Integration. In my case, I call it “s2v-iia-rest2ln-integration“
- Enter a description if you want and then click “Create“
- You will get a clean integration.
- On the right, you have a catalogue of available connectors. Find the Twitter connector that you created and drag and drop it into the right of your integration canvas.
- A wizard will show up.
- Enter the name of your endpoint and description and click Next.
- From the list of operations, select Tweet and click Next.
- Validate and if all is ok, click Done to complete.
- Now, it is time to build the REST connector on the left. On the right panel of connectors, find the REST connector that you built earlier. If you have many, you can enter part of the name at the top and the list will be filtered.
- Once you have your REST adapter on the list of connections, drag and drop it to the left (Drag and Drop a Trigger) section
- It will open the REST connector configuration wizard.
-
Enter the following information:
- What do you want to call your endpoint: TweetAMessageAPI
- What does this endpoint do? This endpoint will receive a message and send it to Twitter adapter, so that it creates a new post
- What is the endpoint’s relative resource URI? /social/tweeter/message
- What action does the endpoint perform? POST
- Configure a request payload for this endpoint: Ticked
- Configure a response payload for this endpoint: Ticked
- Configure CORS (Cross Origin Resource Sharing): Ticked
- What do you want to call your endpoint: TweetAMessageAPI
- Click Next.
- Select the Request Payload Type: JSON
- Click on the <> link and enter a JSON format as you wish to send your POST body payload. Something like:
{“message”:”message”}
- Then, click OK.
- Leave the Media Type to JSON, and click Next.
- CORS Configuration – Allowed Origins: *
- For the response, repeat the steps as in the request. Enter just a simple response that will hold a successful or exceptional response from Twitter.
- Click Next. For the summary, review all and click Done.
- That’s it, we have configured a REST Trigger, as part of this integration.
- The integration should look like this:
- Click on the Map in the middle and then click +
-
In the mapper drag the “message” element under “request-wrapper” into the “status” element on the right.
Notice that the structure within “request-wrapper” is the one that you defined when creating freely the JSON payload that you are expecting as input. Pretty cool huh?
- Click Save on the Mapping window, then you can exit the mapper.
- Now, it is time to implement the mapping for the response (Twitter to the REST invoker):
- Click on the response Map in the middle and then click +
-
For now, simply wire from the left text (which is the echo tweet that you sent originally) to the response, to indicate that the tweet was successful.
Notice that if needed, you could bring more information, such as ids, created time, user, source, etc.
- Click Save on the Mapping window, then you can exit the mapper.
- The integration should look like this:
-
Click on “Tracking”
- Drag and drop the campaign (id) element under “request-wrapper” into the Tracking Field
- Save your integration.
-
Exit the Integration. Notice that your integration is still to be “Activated”, for this click on the slider on the right of the new integration:
- Select to Enable tracing and click Yes.
- Congratulations! Your integration is complete.
- Click the on the link show at the top to see the REST Connector API Metadata of the integration. Otherwise, in case you have lost this popup, simply click on the “i” icon, located on the right end of your Integration.
- When you click on the Metadata link, it will ask you to login. Then, the Metadata API will appear:
- Use Postman, SOAPUI or any other REST Test client to send a REST POST command. I used Postman in this example.
-
In order to get the Endpoint URL, copy the link below and remove the last bit from “metadata”. Then just copy the API that you designed, you can copy it from the metadata page.
In this case: “/social/tweeter/message”
The REST API will be something like this:
https://YOUR_SERVER/integration/flowapi/rest/S2VIIA_REST2TWITT_INT1/v01/social/tweeter/message
The last bit in red represents the actual URI of your API created in ICS.
-
Also, make sure to add the following headers:
- Authorisation: Your ICS credentials
- Content-Type: application/json
- Make sure to change the method to POST and in the body enter the POST body payload in the structure that you created as part of the ICS integration. You can also copy the entered JSON sample from the metadata page:
- In my case I entered this:
{“message”:”Hello world, this tweet came from a quick and easy ICS demo!!! #cloud #ipaas”}
-
As designed, you should get the same text that you sent:
-
Finally, confirm that you see that the tweet went through:
How cool is that?
- Congratulations! You just integrated to Twitter via Oracle Integration Cloud Service.
I hope this blog was useful. Any question, feel free to contact us via LinkedIn or drop a note in this blog.