Integrate Sencha Touch 2.x with Twitter REST API v1.1 - twitter

How to use the REST API of twitter last version with sencha touch 2.x ?

To make requests for some remote api you can use Ext.Ajax.request();
Ext.Ajax.request({
url: 'https://api.twitter.com/1.1/statuses/show.json',
method: 'GET',
params: {
id: 'someId'
},
success: function ( repsonse ) {
},
failure: function ( response ) {
}
});
But be aware of Same-origin policy.

Related

Retrieve data with web api from one localhost application to another localhost application

I'm working with two individual mvc application like A and B. I'm running these two application on localhost(IIS). On application A i have an api controller called student. Now i want these student data through student api and show on application B. How can i retrieve those data through this student api?
i try this ajax request from application B,
$.ajax({
url: 'http://localhost:123/api/StudentApi',
type: "GET",
dataType: "json",
success: function (data) {
console.log(data);
},
error: function (xhr) {
alert(xhr.responseText);
}
});

oauth.io subscribe user to youtube channel

I'm using oauth.io (https://oauth.io/) to authenticate users via google, facebook, etc. How can I subscribe user to youtube channel after authentication ?
OAuth.popup(provider, function(error, result) {
// some code to subscribe user to youtube channel
});
To subscribe a user to a youtube channel, you need to make sure that you have added the following scopes for Youtube to your OAuth.io app:
https://www.googleapis.com/auth/youtube
https://www.googleapis.com/auth/youtubepartner
Also make sure that the Youtube API is activated in your Google API console.
Then, you can subscribe the user through OAuth.io like this:
OAuth.popup('youtube')
.done(function (requestObject) {
requestObject.post('/youtube/v3/subscriptions?part=snippet', {
data: JSON.stringify({
snippet: {
resourceId: {
channelId: 'id_of_the_channel'
}
}
}),
dataType: 'json',
contentType: 'application/json; charset=utf8'
})
.done(function (r) {
// Success: the subscription was successful
console.log(r);
})
.fail(function (e) {
// Failure: the id was wrong, or the subscription is a duplicate
console.log(e);
});
})
.fail(function (e) {
// Handle errors here
console.log(e);
});
You need to specify the dataType and contentType fields as Google API doesn't accept form encoded data.
You can find more information about this Google API endpoint there:
https://developers.google.com/youtube/v3/docs/subscriptions/insert
And if you want to learn more about OAuth.io, you can consult the documentation here:
https://oauth.io/docs/overview
You'll also find a tutorial about the JavaScript SDK here:
https://oauth.io/getting-started?javascript&None
Hope this helps :)

Sending Parse push notifications to multiple applications from single application

I am wondering if it is possible to send push notifications to different IOS applications from only one IOS application via Parse.com API. I can already send a push notification in same application but I want to send to different applications of mine, from a single application.
You can technically use the REST API from Cloud Code, calling back in to Parse with different headers.
Parse.Cloud.httpRequest({
method: "POST",
headers: {
"X-Parse-Application-Id": YOUR_APP_ID,
"X-Parse-REST-API-Key": REST_API_KEY,
"Content-Type": "application/json"
},
body: {
"data": {
"alert": "Yo"
}
},
url: "https://api.parse.com/1/push"
}).then(function() {
console.log("Successful push");
}, function(error) {
console.log(error);
});
Taken from official forums here: Click here

How to POST JSON request in cross domain in sencha touch

I have got following URL
https://development.avalara.net/1.0/tax/get
and would like to POST following JSON request body
{
"DocDate": "2011-05-11",
"CustomerCode": "CUST1",
"Addresses":
[
{
"AddressCode": "1",
"Line1": "435 Ericksen Avenue Northeast",
"Line2": "#250",
"PostalCode": "98110"
}
]
}
which then will give JSON response
{
"DocCode": "78b28084-8d9a-477c-9f26-afab1c0c3877",
"DocDate": "2011-05-11",
"Timestamp": "2011-05-11 04:26:41",
"TotalAmount": 10,
"TotalDiscount": 0,
"TotalExemption": 0,
"TotalTaxable": 10,
"TotalTax": 0.86,
“TotalTaxCalculated”: 0.86,
"TaxDate": "2011-05-11",
.......
}
I have tried to use
Ext.Ajax.request
but get error
Origin http://localhost is not allowed by Access-Control-Allow-Origin.
which might be due to having different domain.
So, then i tried to use JSONP
Ext.data.JsonP.request
(
{
url: 'https://development.avalara.net/1.0/tax/get',
callbackName: 'test',
method: 'POST',
jsonData: '{"DocDate": "2011-05-11", "CustomerCode": "CUST1", "Addresses": [ { "AddressCode": "1", "Line1": "435 Ericksen Avenue Northeast","Line2": "#250", "PostalCode": "98110" } ] }' ,
success: function(response) {
//do some successful stuff
Ext.Msg.alert(response);
},
failure: function(response) {
//complain
Ext.Msg.alert('fail');
}
});
But URL 404(Not Found) error is encountered and request method is GET instead of POST.
Can anyone help me how POST request body(JSON) and obtaind JSON response from different domain?
Thanks in advance
You have four options:
Use CORS. development.avalara.net would need to setup CORS on the server and allow the domain that the Sencha page is running on.
Reverse Proxy requests through a server on the domain that the Sencha page is running on:
Sencha page (mydomain.com) ---> Web Server (mydomain.com) ---> development.avalara.net
Sencha page (mydomain.com) <--- Web Server (mydomain.com) <--- development.avalara.net
You could also POST the form as a regular form post action, or POST the form inside a hidden iframe.
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.Basic-cfg-standardSubmit
Run the Sencha app inside phonegap/cordova which does not block cross-domain requests.
You cannot do JSON-P with POST requests, JSON-P only supports GET requests. Your options are:
Use a GET request with JSON-P
Move the server functionality to the same server your ST app is running
Use something like Cordova and Whitelist the server you want to use for your AJAX POST requests, then use Ext.Ajax.request.

Asp.net MVC Controller Action string parameter doesn't get passed

In my controller I have
public JsonResult GetInfo(string id)
in my js
$.ajax({
contentType: 'application/json, charset=utf-8',
type: "POST",
url: "/Incidents/GetInfo",
data: { id: "777" },
cache: false,
dataType: "json",
success: function (response) {
//etc....
jquery ajax error delegate gets executed. If I use
data: { "777" },
no error, but the value doesn't get passed. This should be easy but I am beating my head against the wall. Maybe I am not allowed to pass strings to controller's actions?
What am I doing wrong here?
You are indicating application/json request and you are sending a application/x-www-form-urlencoded request. So you will have to choose between one of the two ways to encode parameters and not mix them.
application/x-www-form-urlencoded:
$.ajax({
type: "POST",
url: "/Incidents/GetInfo",
data: { id: "777" },
cache: false,
dataType: "json",
...
});
application/json:
$.ajax({
type: "POST",
url: "/Incidents/GetInfo",
contentType: 'application/json, charset=utf-8',
data: JSON.stringify({ id: "777" }),
cache: false,
dataType: "json",
...
});
The JSON.stringify method is natively built into modern browsers and is used to convert the javascript literal into a JSON string which is what we indicated that we are going to send the request as. If you are having to support legacy browsers you could include the json2.js script to your page which contains this method.
As a side note the dataType: "json" setting is not needed since the server will set the proper Content-Type header to application/json and jQuery is smart enough to use that.
And as a second side note you really don't want to be hardcoding an url like this in your javascript file: url: "/Incidents/GetInfo". What you want is to use url helpers when generating urls: url: "#Url.Action("GetInfo", "Incidents")".
Are you missing HttpPost attribute in your action? If not, use something like firebug or chrome dev tools to see http request/response and get more details...
[HttpPost]
public JsonResult GetInfo(string id)

Resources