Will TwitterJS no longer work after May 7th, when the Twitter 1.0 API goes away?
https://code.google.com/p/twitterjs/
Thanks
After looking into this more I'm able to answer my own question: it won't.
The TwitterJS.js API uses 1.0 and v1 methods:
protocol = document.location.protocol.substr(0, 4) === 'http' ? document.location.protocol : 'http:',
URLS = {
search: protocol + '//search.twitter.com/search.json?q=%search%&page=%page|1%&rpp=%limit|100%&since_id=%since|remove%&result_type=recent&include_entities=true', // TODO allow user to change result_type
timeline: protocol + '//api.twitter.com/1/statuses/user_timeline.json?screen_name=%user%&count=%limit|200%&page=%page|1%&since_id=%since|remove%include_rts=%rts|false%&include_entities=true',
list: protocol + '//api.twitter.com/1/%user%/lists/%list%/statuses.json?page=%page|1%&per_page=%limit|200%&since_id=%since|remove%&include_entities=true&include_rts=%rts|false%',
favs: protocol + '//api.twitter.com/1/favorites/%user%.json?include_entities=true&skip_status=true&page=%page|1%&since_id=%since|remove%',
retweets: protocol + '//api.twitter.com/1/statuses/retweeted_by_user.json?screen_name=%user%&include_entities=true&count=%limit|200%&since_id=%since|remove%&page=%page|1%'
},
Related
I am attempting to Unlike a Tweet using Pipedream an integration platform. When I hit Twitter's API for Unlike a Tweet, I get an 404. I double checked and the URL is the same as in the documentation.
const body = {
config: {
method: "post",
url: `https://api.twitter.com/1.1/favorites/destroy.json`,
params : {
id : params.id,
include_entities : params.include_entities
},
},
token: {
key: auths.twitter.oauth_access_token,
secret: auths.twitter.oauth_refresh_token,
}
};
As you can see, the URL from that code is the one specified in the documentation at https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-favorites-destroy
Any advice on how to get this corrected?
Are you sure that the Tweet ID you’re passing as a parameter is correct? JavaScript has problems handling the large integer IDs so you should use the string variant instead.
Here's my code to get around that
for (User users : Spigot.getUsers()) {
if (users.getKnowledgeLevel(KnowledgeTopic.JAVA_CODING) <= 5) {
users.getPlayer().getInventory().addItem(new ItemStack(Material.JAVA_BOOK, 1));
}
}
I am trying to intercept response messages in Swagger using this code:
var full = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
var ui = SwaggerUIBundle({
url: full + "/swagger/v2/swagger.json",
responseInterceptor: function (resp) {
console.log('#response');
return resp;
},
onComplete: function () {
console.log('#onComplete');
}
});
The problem is the response interceptor is called only once (for the https://localhost:5001/swagger/v2/swagger.json file) and it is not called for any API messages.
Is it possible to intercept all swagger API messages?
According to this post it should be possible: https://stackoverflow.com/a/46892528/1882699, but this does not work for me for some reason.
This configuration of Swagger UI works for me is in this post.
The difference is this line:
dom_id: '#swagger-ui',
When this line is used the interceptor intercepts every message. Without this line the interceptor catches only the first message.
i am having a strange problem.
I use OAuth2 and gapi.auth.authorize({client_id:'...',scope:'../youtube',immediate:false}) to log a user into my app. This method lets the user choose which of his connected accounts(identities) to use.
I retrieve user's video using gapi.client.youtube.channels.list and gapi.client.youtube.playlistItems.list.
later in the same app the user can click a button to choose another of his connected accounts(identities). i use again gapi.auth.authorize({client_id:'...',scope:'../youtube',immediate:false}) method.
the problem is that after successfull change of the account the gapi.client.youtube.channels.list method returns the cached result from the first call.
some remarks:
-in ie 11 it works fine
- in google chrome, if i disable the cache from developers tools it also works fine
- before the call to channels.list i call /oauth2/v2/tokeninfo and /plus/v1/people/me and they both return correct results, that is the second account's data
is there any way to correct this?
thank you.
Someone can overcome this by using XMLHttpRequest( see https://developers.google.com/api-client-library/javascript/features/cors) . It's probably a bug of javascript YouTube api.
What worked for me is to introduce a silly extra parameter on the request to cheat Google's system... Or at least that's my impression, because it seems to work consistently:
I just add it to the URL:
"https://www.googleapis.com/youtube/v3/channels?mine=true" +
"&part=" + encodeURIComponent("id,snippet") +
"&key=" + encodeURIComponent(API_KEY) +
"&random=" + encodeURIComponent(Math.random().toString())
Here's the full example:
refreshChannels(): Promise<YoutubeChannel[]> {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
this.channels = JSON.parse(xhr.response).items.map(ch => new YoutubeChannel().deserialize(ch));
console.log("[Youtube][loadChannels] Got some channels:");
console.log(this.channels);
this.onReceivedYoutubeChannels.next(this.channels);
resolve(this.channels);
} else {
reject(JSON.parse(xhr.response));
}
}
};
xhr.onerror = () => reject();
const user = gapi.auth2.getAuthInstance().currentUser.get();
const oAuthToken = user.getAuthResponse().access_token;
xhr.open(
"GET",
"https://www.googleapis.com/youtube/v3/channels?mine=true&part=" +
encodeURIComponent("id,snippet") +
"&key=" +
encodeURIComponent(API_KEY) +
"&random=" + encodeURIComponent(Math.random().toString())
);
xhr.setRequestHeader("Authorization", "Bearer " + oAuthToken);
xhr.send();
});
}
I get different ETags. I saw as well a Cache-Control response header that might be caching too?
cache-control: private, max-age=300, must-revalidate, no-transform
With my solution I can overcome it. If someone understands why it would be great if could elaborate more on this solution.
ok after two days of tryouts i still cant my titanium application to play well with twitter request_token api 1.1, i am always getting 401 unauthorized error .below is my code. i am blocked so any help is appreciated.
var httpClient = Ti.Network.createHTTPClient({
onerror : function(e) {
alert(this.status + ":" + e.error);
},
onload : function(e) {
alert(this.responseText);
if (this.readyState == 4) {
var resposeText = this.responseText;
}
}
});
httpClient.open('POST', "https://api.twitter.com/oauth/request_token");
httpClient.setRequestHeader("content-type", "application/x-www-form-urlencoded; charset=UTF-8");
var now = new Date().getTime();
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var nonce = "";
for (var i = 0; i < 10; ++i) {
var rnum = Math.floor(Math.random() * chars.length);
nonce += chars.substring(rnum, rnum + 1);
}
var parameters = "oauth_callback=" + Ti.Network.encodeURIComponent("http://apicallback.stc.com.sa");
var signature = "POST&" + Ti.Network.encodeURIComponent("https://api.twitter.com/oauth/request_token") + "&" + Ti.Network.encodeURIComponent(parameters);
var header = "OAuth oauth_callback=\"" + Ti.Network.encodeURIComponent("http://apicallback.stc.com.sa") + "\",oauth_consumer_key=\"wPdlchopdYaqHhab8H8jMA\",oauth_nonce=\"" + nonce + "\",oauth_signature=\"" + signature + "\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"" + now + "\",oauth_version=\"1.0\"";
httpClient.setRequestHeader("Authorization", header);
httpClient.send(parameters);
There were several errors :
Your nonce seems to be built incorrectly. Generate a string with 32 letters and encode it with Base 64.
Your signature is not built correctly too. Refer to the Twitter Developers documentation about making signatures. Here are your errors :
All the OAuth arguments are missing but oauth_callback. The OAuth arguments which are used in the Authorize header have to be included in the parameters for the signature
You do not build the key to sign datas.
You do not use the signature method (oauth_signature_method which is set to "HMAC-SHA1") to sign your datas.
Your timestamp is too big. It is the number of seconds since the Unix Epoch time, not the milliseconds. Add a "/1000" :
var now = new Date().getTime() / 1000
More generally have a look at Twitter Developers documentation about authorizing requests : https://dev.twitter.com/docs/auth/authorizing-request
by chance i found javascript library posted in twitter list of libraries. check it out jsOAuth. there is also API doc for the library :). now i am able to get the authorization token but when i perform search by posting to https://api.twitter.com/1.1/search/tweets.json i get 401 (unauthorized) error. now i am stuck again. any idea what might be the problem...
There are multiple twitter libraries out there for appcelerator that already work, I would suggest starting with one of them.
http://www.clearlyinnovative.com/blog/post/33810421717/titanium-appcelerator-quickie-posting-images-to-twitter-with-social_plus-js
see link to github repo at bottom of posting
Has anyone had any experience of using the Google Client API to authorise against their domain by restricting the domain a user can login with?
The titbit that is required appears to be a qs parameter: hd='[Domain name]'
but there's nothing similar in the OAuth2Parameters parameters object
var oap = new OAuth2Parameters
{
AccessToken = Current == null ? null : Current.AccessToken,
RefreshToken = Current == null ? null : Current.RefreshToken,
ClientId = GoogleClientId,
ClientSecret = GoogleClientSecret,
Scope = "https://spreadsheets.google.com/feeds https://docs.google.com/feeds https://www.googleapis.com/auth/userinfo.email",
RedirectUri = HttpContext.Current.Request.Url.Scheme.Concatenate("://", HttpContext.Current.Request.Url.Authority, "/Builder/Authentication/Receive"),
AccessType = "offline" //ensures a refresh token (tho not currently working),
*HD = //Hmm if only... :(((*
};
var authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(oap);
return Redirect(authorizationUrl);
so,in fact, all we need is to adjust the url thus:
var authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(oap);
authorizationUrl += "&hd=" + "mydomain.com".UrlEncode();
return Redirect(authorizationUrl);
Hope that helps someone down the line.
Use hd parameter.
Google documentation
Warning: This tag is documented in OAuth 1.0 API Reference. In version 2 is not documented but works.
Important: OAuth 1.0 has been officially deprecated as of April 20,
2012. It will continue to work as per our deprecation policy, but we encourage you to migrate to OAuth 2.0 as soon as possible.