I use the script php-soundcloud (Oauth 2) and want to change the title (Buy this track) of purchase link.
I can update the link but I can not change the text of link.
I use this code:
$soundcould->put('https://api.soundcloud.com/tracks/56649403', array(
'track[purchase_url]' => 'http://website.com/',
'track[purchase_title]' => 'Support me' // whitout this, it work
));
but it returns me an error: The requested URL responded with HTTP code 422.
When i remove track[purchase_title], it work, so the problem is that variable!
Must be something special to change the link title?
Soundcloud have posed limits on the use of their API?
It's possible to create a new link other than changing the variable purchase_title?
The reason this is not working is because the purchase_url and purchase_title can only be changed on premium accounts. I'll look at making this more clear in the docs!
Here's a code sample that will do the trick for a premium account:
<?php
require_once 'Services/Soundcloud.php';
$client = new Services_Soundcloud('client_id', 'client_secret', 'redirect_uri');
$client->setAccessToken('your-access-token');
$track_url = 'https://api.soundcloud.com/tracks/52652023.json';
$response = json_decode($client->put($track_url, array(
'track[purchase_url]' => 'http://website.com',
'track[purchase_title]' => 'Support me'
)));
?>
If that doesn't work, the problem is elsewhere. Email me and I can help you debug further.
I am not sure but try it. I think it is help full to you :-
See the guide:-
http://developers.soundcloud.com/docs/api/guide
Try it
<?php
$track = <<<EOH
<track>
<downloadable>true</downloadable>
<purchase_url>http://website.com/</purchase_url>
<purchase_title>true</purchase_title>
</track>
EOH;
try {
$response = json_decode(
$soundcloud->put(
'tracks/1',
$track,
array(CURLOPT_HTTPHEADER => array('Content-Type: application/xml'))
),
true
);
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}
Related
I created a function in PHP that downloads a map created in google maps, I am able to download, however, the route is not coming when I am saving.
How the picture is coming:
How it should come:
Code:
function download_remote_file_with_curl($file_url, $save_to) {
$arrContextOptions = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
),
);
$response = file_get_contents($file_url, false, stream_context_create($arrContextOptions));
//echo $response;
//file_put_contents($save_to, $response);
$downloaded_file = fopen($save_to, 'wb');
fwrite($downloaded_file, $response);
fclose($downloaded_file);
}
$urlDownload = "https://maps.googleapis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CcJd]}BjPkG|y#gPptBu]byE_H~gArB`EfG|FxXnYfv#nv#nWhX`RjRjHj`#bfBdgKlCrKzGhQp`#lbAtdBnjEr_#z`A`~#n}Bth#fuAdpDzdJ|W`o#`ClAxIj#beA~A~p#bAx|F~I`lEzGvwAbCdMx#neDjlAbp#hUrE}#prB_qCzBaAjJAxOKhWfAfP?tm#}Q~{Bkr#r{EeyAxPoApfB~WzK|AHTdBDrO}A~RmBrXsCzZuA~NJx#bD|#dAfX`#{#nG&markers=color:green|label:A|-10.8819552,-61.95483539999998&markers=color:red|label:B|-12.457280801085,-64.2310285267651&key=yourkey";
download_remote_file_with_curl($urlDownload, realpath('C:/test') . '/' . 'test' . '.jpg');
?>
Thank you!
I don't know if what I'm about to write makes sense, but the route that you want to download is an item that appears once it's selected.
For example when the "SKIP" buttom in Youtube appears to quit an advertisement, it creates an instance of that box in HTML, and then it dissappears when Add is over.
I think that the route is this kind of instance and you must add a line of code to also take that piece of html
I have a problem with Facebook Real-time subscription from my facebook page.
When I POST a subscription, i get the message from facebook about it to my call back url.
Code:
$session = new FacebookSession('<APP ACCESS TOKEN>');
$request = new FacebookRequest(
$session,
'POST',
'/<APP ID>/subscriptions',
array(
'object' => 'page',
'callback_url' => 'http://*************/facebook/callback.php',
'fields' => 'conversation', // a try 'feed' to
'verify_token' => '<VERIFY TOKEN>',
)
);
$response = $request->execute();
BUT when someone add a post/conversation to my fb page, facebook don't send me any data.
callback.php code:
<?php
// Insert the path where you unpacked log4php
include('log4php/Logger.php');
// Tell log4php to use our configuration file.
Logger::configure('config.xml');
// Fetch a logger, it will inherit settings from the root logger
$log = Logger::getLogger('myLogger');
// Start logging
$log->warn($_REQUEST); // Logged because WARN >= WARN
require_once __DIR__ . '/facebook-php-sdk-v4-5.0-dev/src/Facebook/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\Authentication\AccessToken;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
//define('VERIFY_TOKEN', '*******');
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'GET' && $_GET['hub_mode'] == 'subscribe' && $_GET['hub_verify_token'] == '<VERIFY TOKEN>') {
echo $_GET['hub_challenge'];
$log->warn($_GET);
$log->warn($_POST);
} else if ($method == 'POST') {
$updates = json_decode(file_get_contents("php://input"), true);
// Here you can do whatever you want with the JSON object that you receive from FaceBook.
// Before you decide what to do with the notification object you might aswell just check if
// you are actually getting one. You can do this by choosing to output the object to a textfile.
// It can be done by simply adding the following line:
// file_put_contents('/filepath/updates.txt',$updates, FILE_APPEND);
$log->warn($updates);
$log->warn($_GET);
$log->warn($_POST);
error_log('updates = ' . print_r($obj, true));
}
Thank you for your help !
There is currently an open bug with Facebook support:
https://developers.facebook.com/bugs/709097499224897/
So it's possible that this is a temporary issue...
What's the output of /{your-app-id}/subscriptions?
According to your code you subscribed to /conversations which requires read_page_mailboxes permissions. You probably want to try a simple page feed subscription first to see if this works.
RTU updates seem to be back to normal since yesterday, but deleting your subscriptions and re-subscribing might be worth a try, too, since you probably subscribed to a black hole when RTU had issues yesterday.
I find answer with a big help from facebook developers forum friends :)
My code to make subscription and callback code is good. But to get conversations or feed it is not enough. I have to add my app to my page as a subscribed_app using request in graph api:
POST
{page-id}/subscribed_apps
the docs for this operation is on:
https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps/
My hackathon team has been working the last 12+ hours to use Google Glass and the Mirror API to play a video, specifically using the PHP Library.
We have tried attaching a video to a timeline item and we have tried using the bundle option, but neither will stream the video.
I don't have an error message to show, and the code as far as we can see is correct, based on the Google Documentation.
Some more details:
We're using an API to access a video hosted on AWS
We've also tested using videos hosted on other sites as well as
smaller-sized videos (the one we're aiming to use is 20+MB
If anyone can offer some guidance, we'd really appreciate it! Thank you!
EDIT
This is the code structure we're using, straight from the PHP library:
function insertAttachment($service, $itemId, $contentType, $attachment) {
try {
$params = array(
'data' => $attachment,
'mimeType' => $contentType,
'uploadType' => 'media');
return $service->timeline_attachments->insert($itemId, $params);
} catch (Exception $e) {
print 'An error ocurred: ' . $e->getMessage();
return null;
}
}
And here is the latest iteration of trying to get the video to stream:
$bundle_view = $app->view();
$bundle_view->appendData(array('total' => count($response['search']), 'video'=>$response['search'][0]));
$bundle_html = $app->view()->fetch('bundle_home.twig');
$new_timeline_item = new Google_TimelineItem();
$new_timeline_item->setHtml($bundle_html);
//$new_timeline_item->setBundleId($response['search'][0]['id']);
$new_timeline_item->isBundleCover = 'true';
$notification = new Google_NotificationConfig();
$notification->setLevel("DEFAULT");
$new_timeline_item->setNotification($notification);
$post_result = insert_timeline_item($mirror_service, $new_timeline_item, null, null);
error_log(print_r($post_result->getId(), true));
$new_timeline_item->setHtmlPages("<article><section> <video src='http://www.w3schools.com/html/movie.mp4' controls> </section></article>");
/**
foreach ($response['search'] as $video) {
$item = $video['videos'][0];
$v_item = new Google_MediaFileUpload('video/vnd.google-glass.stream-url', $item, true);
$params = array(
'data' => $v_item,
'mimeType' => 'video/*',
'uploadType' => 'resumable');
$mirror_service->timeline_attachments->insert($post_result->getId(), $params);
}
**/
insert_timeline_item($mirror_service, $new_timeline_item, null, null);
Might be easier to read in a Gist: https://gist.github.com/kgardnr/1f2ce243f91cedaf9c92
It appears to be that in setHTMLPages where video element is used which is a blocked HTML element. Is it a root cause of the issue?
Streaming video currently can't be attached through HTML, and I don't believe you can render anything on top of it. From my experience, it's also not well (or at all) included in the libraries (at least not the .NET one...I assume the PHP one is the same).
What I had to do was to build the webrequest myself, as laid out here: https://developers.google.com/glass/timeline in the streaming video section
I want to post some text automatically to my application twitter account. I create an account for that and take all the needed information and write a php code for it. it is simple code:
I made it just to test the post ability :
<?php
require_once 'oauth/twitteroauth.php';
$message = "hiiiiiii"; #actual message to twitter
define("CONSUMER_KEY", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("CONSUMER_SECRET", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("OAUTH_TOKEN", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("OAUTH_SECRET", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
print_r($connection);
$content = $connection->get('account/verify_credentials');
//print_r($content);
$connection->post('statuses/update', array('status' => $message));
?>
I get the information from the account so i think the connection is working but why i can not post any thing? i tried to post this message but after executing this code nothing happened on my twitter no new tweet is shown????
$connection->post is a method :
/**
* POST wrapper for oAuthRequest.
*/
function post($url, $parameters = array()) {
$response = $this->oAuthRequest($url, 'POST', $parameters);
if ($this->format === 'json' && $this->decode_json) {
return json_decode($response);
}
return $response;
}
My first port of call if you are able to receive information from the account using those credentials, would be that your app has read AND write (posting) permissions:
Go to dev.twitter.com/apps. Select your app, then under 'settings' -->
'application type' you will find what you need.
Although that didn't work, no matter what you changed in your code posting to your account through this app wouldn't work as that functionality was outside the permissions you set yourself. So now we know that you're able to post:
Change
$connection->post('statuses/update', array('status' => $message));
To
$result = $connection->post('statuses/update', array('status' => $message));
Then see what the value of $result is. This might provide some clues
Ok so the response is telling you, you still don't have permissions, you need to regenerate your token and access credentials then update your code with them:
define("CONSUMER_KEY", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("CONSUMER_SECRET", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("OAUTH_TOKEN", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("OAUTH_SECRET", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
Those credentials still have the previous permissions attached to them, when you request new token, it will reference the new permissions and allow you to post.
I've got the basic idea covered (I think), but can't seem to successfully post anything using Facbook's provided PHP class. Given this example, can anyone see anything that might be the problem?
// Initialize Facebook API
$fb = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => true
));
if($fb->getSession()) {
$res = $fb->api('/me/feed/', 'post', array(
'message' => 'test message',
'description' => 'testing'
));
}
var_dump($res);
When I output the contents of $res I get a face-palming NULL. Any ideas? If the above looks correct, can anyone suggest some things I might try to debug this?
In your app, when you check to see if the user is logged into Facebook, make sure you are confirming that your app requested the 'special privilege' of posting to the user's wall. You can do this by modifying your code as follows:
$url = $this->facebook->getLoginUrl(array('canvas' => 1, 'fbconnect' => 0, 'req_perms' => 'user_status,publish_stream'));
Note the req_perms key being set to a list of values including 'publish_stream'. If you don't have this privilege the feed call will fail.
Also whether this is really the problem or not, you can wrap your Facebook requests with a try-catch block to catch FacebookApiException type exceptions to get more information when you have errors. For example:
try {
$uid = $this->facebook->getUser();
$me = $this->facebook->api('/me');
} catch (FacebookApiException $e) {
print_r($e);
}