Does the Dailymotion API have something equivalent to YouTube's onYouTubeIframeAPIReady? - dailymotion-api

With the YouTube JS API, I can do the following:
<script src="//www.youtube.com/player_api"></script>
<script language="javascript">
function onYouTubeIframeAPIReady() {
ytPlayer = new YT.Player('ytplayer');
}
</script>
This will load the API, and when its ready, assign ytPlayer.
However, the Dailymotion API is included as follows:
<script src="//api.dmcdn.net/all.js"></script>
<script>
DM.init();
</script>
This doesn't wait for the API to be ready. So I'll often get Uncaught ReferenceError: DM is not defined errors. Does Dailymotion have a way to wait for the API to be ready before it executes code?

The most efficient way to load the SDK in your site is to load it asynchronously: example loading asynchronously
You can then subscribe to the event 'apiready'
event subscribe documentation
list of events

Related

Integrating Twilio-js in Angular.js?

Can anyone please guide me how do I integrate/require twilio.js file in the my application? I have to do it with angular.js app. I can't require/include it and can't get the Twilio object to call it's methods. I'm really new to it!
By just adding following script tag do not makes me able to use Twilio object:
<script type="text/javascript" src="//media.twiliocdn.com/sdk/js/client/v1.4/twilio.js"></script>
Results:
Update:
As per #philnash help I've resolved the previous error and now this is how my code looks like is:
<script type="text/javascript" src="//media.twiliocdn.com/sdk/js/client/v1.4/twilio.js"></script>
<script>
Twilio.Device.setup(#token, { debug: true, region: "ie1" });
Twilio.Device.ready(function(device) {
// The device is now ready
alert("Twilio.Device is now ready for connections");
});
</script>
But I'm getting the below error:
Any help will be appreciated!
Twilio developer evangelist here.
When using the Twilio Client JavaScript, there is no Twilio.setup function.
Instead, you should use Twilio.Device.setup.
Let me know if that helps at all.

How to get data of a youtube playlist in JSON format using JavaScript API V3

Youtube stopped support to V2 I'm using till now, can anyone tell me how to get data of a youtube playlist in JSON format using JavaScript API V3
V2 URL I used is as given below
http://gdata.youtube.com/feeds/api/playlists/{PLAYLIST_ID}?alt=json-in-script&callback=showMyVideos
Resolved
v3 URL is
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId={PLAYLIST_ID}&key={KEY}
There are a number of sample applications for the Javascript v3 client library that can be found here:
https://developers.google.com/youtube/v3/code_samples/javascript
The call you are probably after is PlaylistItems:list and can be seen here:
https://developers.google.com/youtube/v3/docs/playlistItems/list
and can be called using:
GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&id=YOUR-PLAYLIST-ID&key={YOUR_API_KEY}
Something along these lines will get details of the first 50 records in a specified playlist using the Javascript client library. The result is stored in the response object.
<!doctype html>
<html>
<head>
<title>YouTube</title>
</head>
<body>
<script>
function onGoogleLoad() {
gapi.client.setApiKey('{YOUR-API-KEY}');
gapi.client.load('youtube', 'v3', function() {
var request = gapi.client.youtube.playlistItems.list({
part: 'snippet',
playlistId: '{PLAYLIST-ID-HERE}',
maxResults: 50
});
request.execute(function(response) {
for (var i = 0; i < response.items.length; i++) {
console.log(response.items[i].snippet.title + " published at " + response.items[i].snippet.publishedAt)
}
});
});
}
</script>
<script src="https://apis.google.com/js/client.js?onload=onGoogleLoad"></script>
</body>
</html>

Where can I find the latest /jsbin/www-widgetapi file?

I'm currently loading the YouTube API like so:
$(function () {
// This code will trigger onYouTubePlayerAPIReady
$('<script>', {
src: 'https://s.ytimg.com/yts/jsbin/www-widgetapi-vflwt8QCF.js',
async: true
}).insertBefore($('script:first'));
});
I was looking at the YouTube demo page, https://developers.google.com/youtube/youtube_player_demo, and I noticed in their source that they were using a different URL to load their widget API:
<script src="https://s.ytimg.com/yts/jsbin/www-widgetapi-vfl4qCmf3.js" async></script>
I thought that this might be a more up-to-date version of their API. So, I swapped it out, but I receive an error message:
Uncaught ReferenceError: YTConfig is not defined
I'm left wondering which of these is the correct location, if either, to be loading the most up to date widgetapi data from. Is there a location for this info?
to get the latest API version I suggest to use example from YT reference:
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
this'll make sure the latest version is being loaded
if you really need to grab latest version for some reason just check this url:
https://www.youtube.com/iframe_api
and get it from the source code

Google Chrome Extension with OAuth

I am trying to integrate OAuth with my chrome extension. I am following the tutorial by google: https://developer.chrome.com/extensions/tut_oauth.html
I create ExOauth from the background.js (defined by me and it is loaded by background.html).
var oauth = ChromeExOAuth.initBackgroundPage({
'request_url': 'https://www.google.com/accounts/OAuthGetRequestToken',
'authorize_url': 'https://www.google.com/accounts/OAuthAuthorizeToken',
'access_url': 'https://www.google.com/accounts/OAuthGetAccessToken',
'consumer_key': 'anonymous',
'consumer_secret': 'anonymous',
'scope': 'https://docs.google.com/feeds/',
'app_name': Test app'
});
oauth.authorize(onAuthorized);
Here is the OnAuthorized method:
onAuthorized = function () {
// Start my application logic.
};
Am I missing something here? When I load the extension, it opens up several "Redirecting...." tabs.
The tutorial seems to be missing one file. If you open chrome_ex_oauth.html, you'll see that it tries to load 3 js files:
<script type="text/javascript" src="chrome_ex_oauthsimple.js"></script>
<script type="text/javascript" src="chrome_ex_oauth.js"></script>
<script type="text/javascript" src="onload.js"></script>
The onload.js file is not provided. The OAuth contacts example provides such a file, with the following content:
window.onload = function() {
ChromeExOAuth.initCallbackPage();
}
After adding this file, it seems to work just fine.
I know the Question is a bit older but i had the same Problem.
I made the mistake that i want to authenticate two oauth endpoint and call both times the ChromeExOAuth.initBackgroundPage({})
Obviously that's wrong cause i dont want to init my background page twice.
Maybe using the ..._oauthsimple.js will fix that

Error "Origin null is not allowed by Access-Control-Allow-Origin" in jsOAuth

I'm trying to use the twitter API with library jsOAuth.
Full html
<div id="message">Loading..</div>
<script src="jsOAuth-1.3.3.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-1.7.min.js" type="text/javascript"></script>
<script type="text/javascript">
var oauth = OAuth({
consumerKey: "-MY-KEY-",
consumerSecret: "MY-SECRET"
});
Updated
oauth.get("http://api.twitter.com/1/statuses/home_timeline.json?callback=?", success, failure);
function success(data){
$("#message").html("Sucess: " + data.text);
var timeline = jQuery.parseJSON(data.text);
console.log(timeline);
$.each(timeline, function (element){
console.log(element.text);
});
}
function failure(data) {
console.log("Throw rotten fruit, something failed");
$("#message").html("Error" );
}
</script>
Result
Full image
Questions
What am I doing wrong?
How can I use the twitter API in my PC.
If you can send me I would appreciate any examples.
Thank you all.
What am I doing wrong?
You are trying to make an AJAX request to Twitter. You are violating cross domain access policies - you cannot access data on the Twitter domain.
How can I use the Twitter API on my PC?
Pick one :
Use JSONP
Use a server-side proxy
Store your code on a file:// path, which removes the cross domain restrictions
Change your browser's security settings to allow this kind of access.
I have styled the unlikely ones in italic.
Also, as an experienced Twitter developer, I have one important note to make about your code: you're using Javascript to access the API. While using JS to do that isn't disallowed, using OAuth in javascript is very unsafe and your application will be blocked from the Twitter API if you used this code on a website.

Resources