Soundmanager2 Soundcloud API crossdomain.xml - soundcloud

I am using Soundmanager2 to stream files from soundcloud and display Eq visuals, but I'm having trouble with getting the eqdata when pausing or changing a track.
Shown here
I understand that Flash is unable to access the metadata due to the cross domain policy defined in the "crossdomain.xml" file on soundcloud as seen in this post: (and many others)
How to use SoundManager2 to stream from SoundCloud, and make visualizations?
I realize that I have to resolve the track's stream_url before loading it into sound manager. I'm doing this with an ajax call to a php script that resolves the url (shown below):
var client_id = '866143113772fec9556700f7f88f3abc',
url = 'http://api.soundcloud.com/resolve.json?url=http://soundcloud.com/aries-audio-music/tracks&client_id=';
$.getJSON(url+client_id+'&callback=?', function(playlist){
$.each(playlist, function(index, track) {
//append to playlist
$('<li id="tr-'+track.id+'">' + track.title + '</li>').data('track', track).appendTo('.tracks');
//get resolved stream url
$.ajax({
type: 'GET',
url: 'get_sc_url.php?id='+track.id,
success: function(data) {
console.log(data);
sm2_addtrack(track, data); //create SM2 sound object with resolved url
}
});
});
});
function sm2_addtrack(track, stream_url) {
soundManager.createSound({
id: 'track_' + track.id,
url: stream_url,
usePolicyFile : true,
usePeakData: false,
useWaveformData: false,
useEQData: true,
.....
get_sc_url.php used to resolve stream_url
<?php
require 'include/referrer_check.php';
require 'include/SC_API_KEY.php';
require 'include/API_cache.php';
$track_id = intval($_GET['id']);
$key = get_soundcloud_api_key();
$api_call = 'http://api.soundcloud.com/tracks/'.$track_id.'/stream/?client_id='.$key;
function get_web_page($url) {
/*
* hat tip: http://forums.devshed.com/php-development-5/curl-get-final-url-after-inital-url-redirects-544144.html
*/
$options = array(
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => false, // return web page
CURLOPT_HEADER => true,
CURLOPT_NOBODY => true,
CURLOPT_CONNECTTIMEOUT => 5, // timeout on connect
CURLOPT_TIMEOUT => 5, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_RETURNTRANSFER => true, // return web page
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
return $header;
}
$myUrlInfo = get_web_page($api_call);
echo $myUrlInfo["url"];
?>
The result I am getting is something like this:
ec-media.soundcloud.com/Ez0B3lUZjjCR.128.mp3?f10880d39085a94a0418a7ef69b03d522cd6dfee9399eeb9a52200996dfabd3cefb29b7554ff4fd02baab5100d3a070e07d55f6e1eb41808c65398ce84cd496788c171f7e4&AWSAccessKeyId=AKIAJNIGGLK7XA7YZSNQ&Expires=1415223069&Signature=A0qaC1Nr3%2FXw4jwFYMjA%2F98arwI%3D
which plays but gives me no spectrum data at all and I still get the
computeSpectrum() (EQ data) SecurityError: Error #2123
from soundmanager2.
I know for sure that ec-media.soundcloud.com/crossdomain.xml is being downloaded, but I still can't solve this problem.

I think it may be because I'm trying to access the soundcloud crossdomain.xml policy file (which is HTTPS) from a HTTP document. secure="false" is not defined in Soundcloud's crossdomain.xml policy file so it defaults to secure="true", therefore the SWF can not access anything.
I doubt Soundcloud will ever set secure="false" in their crossdomain.xml for obvious reasons (it defeats the purpose of even having HTTPS).
I "think" this is why I get computeSpectrum() (EQ data) SecurityError: Error #2123, but I don't have access to a HTTPS enabled server to test this so I could be wrong.

Related

Where can I find others callback of infinite grid store?

I use an Infinite Grid, actually all work fine but in the PHP that the store uses I do a request to an external webservice.
This is my Store Load:
myInfGrid.getStore().load({
scope : this,
url : 'download.php',
params : { },
callback: function(records, operation, success) {
if (success) {
// Here a process is done only once time even
// for others automated launched requests
}
}
});
My download.php file contains a curl request to a webservice like below.
Sometimes the WebService takes a very long time to answer.
...
$url = "https://external_webservice";
$params = array('callback' => $callback,
'q' => $query,
'rows' => $rows,
'sort' => $sort,
'start' => $start);
$url .= '?' . http_build_query($params);
$myCurl = curl_init($url);
curl_setopt($myCurl, CURLOPT_RETURNTRANSFER, true);
$fetchResult = curl_exec($myCurl);
curl_close($myCurl);
// HERE my process of $fetchResult content
...
I would like to extract this WebService Curl call and put it only on each callback.
My problem is: I don't know where are others callbacks.
I mean callbacks associated to all requests that are launched automatically by the infinitegrid ?

What is this? (Facebook Offline Conversions API) Error #21009 - The data set upload is temporarily not ready

We have been uploading to Facebook's Offline Conversion API for the past 3 weeks with no issues. Suddenly, Facebook is returning this error:
(#21009) The data set upload is temporarily not ready.
See below code for full JSON payload.
Our Auth Token is still valid. (e.g. Not expired, still valid)
According to this tool: https://developers.facebook.com/tools/debug/accesstoken/
# I had to remove these fields for privacy reasons
define('FACEBOOK_APP_ACCESS_TOKEN', 'YOUR TOKEN HERE');
define('FACEBOOK_PIXEL_OFFLINE_EVENT_SET_ID', 'YOUR PIXEL ID HERE');
# Be sure to change the email/name fields accordingly
$event_name='test-upload';
$data = array();
$data["match_keys"] = array();
$data["match_keys"]['email'] = hash('sha256', 'bob.ross#example.com');
$data["match_keys"]['fn'] = hash('sha256', 'bob');
$data["match_keys"]['ln'] = hash('sha256', 'ross');
$data["match_keys"]['gen'] = hash('sha256', 'm');
$data["event_time"] = time();
$data["event_name"] = $event_name;
$data["currency"] = "USD";
$data["value"] = '0.00';
// Turn Data to JSON
$data_json = json_encode(array($data));
// Fill available fields
$fields = array();
$fields['access_token'] = FACEBOOK_APP_ACCESS_TOKEN;
$fields['upload_tag'] = $event_name . '-' . time(); // You should set a tag here (feel free to adjust)
$fields['data'] = $data_json;
$url = 'https://graph.facebook.com/v3.2/' . FACEBOOK_PIXEL_OFFLINE_EVENT_SET_ID . '/events';
$curl = curl_init($url);
curl_setopt_array($curl, array(
// Replace with your offline_event_set_id
CURLOPT_URL => 'https://graph.facebook.com/v3.2/' . FACEBOOK_PIXEL_OFFLINE_EVENT_SET_ID . '/events',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => http_build_query($fields),
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
//"content-type: multipart/form-data",
"Accept: application/json" ),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Expected result from Facebook:
{"id":"36485444079550","num_processed_entries":1}
Actual result from Facebook
{
"error": {
"message": "(#21009) The data set upload is temporarily not ready.",
"type": "OAuthException",
"code": 21009,
"fbtrace_id": "GeofD5QsXdI"
}
}
I would add a comment instead of an "answer" but I don't quite have the points yet. The commenters on the Facebook thread (https://developers.facebook.com/support/bugs/1052442614962359/) have had this magically resolve overnight, and I experienced the same (problem happening and no explanation, then magical resolution and no explanation). It seems like Facebook may have fixed whatever was causing the issue.

How to integrate instamojo payment gateway with codeigniter rest server?

I am trying to integrate Instamojo Payment Gateway within Chris Kacerguis’ REST Server.
Problem:
The below code:
public function instamojotest_post()
{
$api = new Instamojo\Instamojo(‘abcd1234’, ‘efgh5678’, 'https://test.instamojo.com/api/1.1/');
try {
$response = $api->paymentRequestCreate([
'amount' => 100,
'purpose' => 'New Product Purchase',
'buyer_name' => 'Test User',
'email' => 'testuser#gmail.com',
'phone' => '9876543210',
'redirect_url' => 'http://www.example.com/products_api/validate_payment'
]);
header('Location: ' . $response['longurl']);
} catch (Exception $e) {
$this->response([
'success' => false,
'message' => $e->getMessage()
], 500);
}
}
is not redirecting to the Instamojo Payment Site and no error is being displayed.
It is working fine and redirecting successfully with vanilla CodeIgniter.
Questions:
1) Is it, at all, possible to redirect from within a REST Server Post Method?
2) If the above is possible, then what is wrong with my code?
3) Is there any other way to achieve what I am trying to do?
I found many tutorials on the internet but none of them are using REST Server.
I stumbled accross this question while Googling. I was also facing the same issue and here is how I solved it.
Note: This is not exactly a solution but a work-around. Also I admit that this may not be the best solution out there, but it worked for me.
I returned the payment url from the Rest Server, and redirected to the url from within the Rest Client.
Rest Client Code:
class Test extends CI_Controller
{
public function instamojo_make_payment()
{
$url = "http://www.example.com/products_api/instamojotest";
$params = []; //You will obviously be needing this in real life implementation :)
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($curl_handle);
curl_close($curl_handle);
if ($response['success'])
header('Location: ' . $response['payment_url']);
else
$this->load->view('payment_failed_page');
}
}
Rest Server Code:
class Products_api extends REST_Controller
{
public function instamojotest_post()
{
$api = new Instamojo\Instamojo('abcd1234', 'efgh5678', 'https://test.instamojo.com/api/1.1/');
try {
$response = $api->paymentRequestCreate([
//Make sure to pass these data from the Rest Client
'amount' => 100,
'purpose' => 'New Product Purchase',
'buyer_name' => 'Test User',
'email' => 'testuser#gmail.com',
'phone' => '9876543210',
'redirect_url' => 'http://www.example.com/products_api/validate_payment'
]);
$this->response([
'success' => true,
'payment_url' => $response['longurl']
], 200);
} catch (Exception $e) {
$this->response([
'success' => false,
'message' => $e->getMessage()
], 500);
}
}
}
While giving this answer I assumed that the Api is open. If it is not, then make sure to pass your credentials when making the curl call.
Update
Thanks to #AshwiniChaudhary's comment below, which states that:
REST APIs are not meant for redirection. REST API returns JSON, XML
etc and the receiver takes care of whatever is supposed to be done.
the actual reason behind the fact, "why REST Server is not letting us to perform the redirect", becomes pretty clear.

Can I use Dropzone.js to send files directly to Facebook instead of first uploading them to my sever?

I can post images to a user's event stream using Dropzone.js using HTML, Javascript and PHP:
HTML
<form action="PHP/uploads.php" class='dropzone' id='fbDropZone'></form>
Javascript
Dropzone.autoDiscover = true;
Dropzone.options.fbDropZone = {
init: function () {
fbDropZone = this;
$("#removeAllImages").click(function () {
fbDropZone.removeAllFiles();
});
},
previewTemplate: '<div class="dz-preview dz-file-preview"><div class="dz-details"><div class="dz-filename"><span data-dz-name></span></div><div class="dz-size" data-dz-size></div><img data-dz-thumbnail /></div><div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div><div class="dz-success-mark"><span>✔</span></div><div class="dz-error-mark"><span>✘</span></div><div class="dz-error-message"><span data-dz-errormessage></span></div></div>',
paramName: "file",
maxFilesize: 5,
maxFiles: 1,
autoProcessQueue: false
};
And then this PHP is called when a <DIV> is clicked on:
$config = array(
'appId' => $app_id,
'secret' => $app_secret,
'scope' => $required_permissions,
'fileUpload' => true,
'allowSignedRequest' => false,
);
$facebook = new Facebook($config);
$facebook->setAccessToken($_COOKIE['fbAccessToken']);
$eid = $_COOKIE['eid'];
$ds = DIRECTORY_SEPARATOR;
$storeFolder = 'uploads';
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds;
$targetFile = $targetPath. $_FILES['file']['name'];
move_uploaded_file($tempFile,$targetFile);
$photo_return = $facebook->api($eid.'/photos', 'POST', array('source' => '#'.$_FILES['file']['name'], 'message' => 'This post from a DropZone'));
}
Thing is I'd like to pass the image directly from the user's drive to FB without going via my server. Can anyone point me towards some code to do this? Or is it just not possible as security issues prevent me from knowing exactly where the file is on a user's device/computer?
When a user posts a file, you receive the file stream. You may know the user's file path, but it's irrelevant if you're not in the same computer.
As far as I know, you should be able to send the file stream from your server to Facebook directly with no security issues, but sending just a file path would be of no help.
If you really want to send a file without receiving it in your server, then you should program a Javascript-only solution, but that would require a Facebook JS API with file upload support. I'm not aware if such a thing exists.

SugarCRM REST api error

I am trying to retrieve custom module data through the Sugarcrm REST api but I am not able to do so as I am not even able to login with the documentation code, I tried same thing as given in documentation
<?php
// specify the REST web service to interact with
$url = 'localhost/~jmertic/sugarcrm/service/v4_1/rest.php';
// Open a curl session for making the call
$curl = curl_init($url);
// Tell curl to use HTTP POST
curl_setopt($curl, CURLOPT_POST, true);
// Tell curl not to return headers, but do return the response
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Set the POST arguments to pass to the Sugar server
$parameters = array(
'user_auth' => array(
'user_name' => 'username',
'password' => md5('password'),
),
);
$json = json_encode($parameters);
$postArgs = array(
'method' => 'login',
'input_type' => 'JSON',
'response_type' => 'JSON',
'rest_data' => $json,
);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postArgs);
// Make the REST call, returning the result
$response = curl_exec($curl);
// Convert the result from JSON format to a PHP array
$result = json_decode($response);
if ( !is_object($result) ) {
die("Error handling result.\n");
}
if ( !isset($result->id) ) {
die("Error: {$result->name} - {$result->description}\n.");
}
// Get the session id
$sessionId = $result->id;
changed the username,password and url to match my setup but i get an error stating
No direct script access allowed
I tried to search this on web but couldnt find any relevant solution.
I am using sugarCRM 6.5.0RC2 version
Regards,
Anand Joshi
You probably has some defense configured on your WEB server which allows you to access only to index.php.
To verify it, try to go from the browser to your API URL: http://YOUR_DOMAIN_NAME/service/v4_1/rest.php
Or/and run from terminal: wget http://YOUR_DOMAIN_NAME/service/v4_1/rest.php
If it shows the same message, check your .httaccess on this folder or/and your web server config file.
If no, how do you run the API test script? through CLI or from browser?
Also I suggest you to use some Open Source SugarCRM REST API Wrapper. I use this one: https://github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class
Shouldn't the line be this...
$url = 'http://yoursugarinstance/service/v4_1/rest.php';