Okay, so I'm using php to post soundcloud widgets on my website(no need to explain why and how because thath's not wath's important)
Here is my code:
if (strpos($post['link'], 'soundcloud.com') !== FALSE)
{
echo "<iframe width=\"500\" height=\"150\" scrolling=\"no\" frameborder=\"no\"
src=\"https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/".$trackID."&color=ff6600&auto_play=false&show_artwork=true\"></iframe>";
}
My variable $post['link'] outputs the soundcloud link in this form https://soundcloud.com/alex-oancea/best-thing-about-you-original
What I would like to do is get the track's id from the link and declare it as $trackID because as you can see in my code(in the src="" part), the widget uses the track's ID
I have looked into the soundcloud API and many other threads on this site but I didin't find how to do this or how to write the code...
Thanks in advance!
Check http://developers.soundcloud.com/docs#resolving
You can click the PHP button on the example and get a good way of getting a track ID:
<?php
require_once 'Services/Soundcloud.php';
// create a client object with your app credentials
$client = new Services_Soundcloud('YOUR_CLIENT_ID');
// a permalink to a track
$track_url = 'http://soundcloud.com/forss/voca-nomen-tuum';
// resolve track URL into track resource
$track = json_decode($client->get('resolve', array('url' => $track_url)));
Now $track->id is your track ID.
Just be aware you need the SoundCloud API for this, and you'll probably have to register your app with SoundCloud to use the service. I have not had personal experience with any of this so I can't provide any information about those processes.
If you experiment on your local machine (xampp in your case), you CANNOT make it work, beause the 'REDIRECT_URL' cannot be anything else but a valid link to a hosted domain. The API just does not accept (for the good reason) url's containing "localhost" or or "192.168.x.x"-style url's. This is simply because the API really sends info to the 'REDIRECT_URL' and it needs to be able to reach it.
You need to get in touch with your hosting provider and setup a "live" dev environement.
Assuming you are using the php-soundcloud from the mptre's Github:
Check https://developers.soundcloud.com/docs#resolving (and even the '/resolve' indicated in the 'see also' section).
You can get a good way of getting a track ID by this way:
<?php
require_once 'Services/Soundcloud.php';
// create a client object with your app credentials
$client = new Services_Soundcloud('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
// a permalink to a track
$track_url = 'http://soundcloud.com/forss/voca-nomen-tuum';
// resolve track URL into track resource
$track = json_decode($client->get('resolve', array('url' => $track_url), array(CURLOPT_FOLLOWLOCATION => true)));
// display all the information from that track resource
var_dump($track);
Now $track->id is your track ID.
?>
Just be aware you need the SoundCloud API for this, and you have to register your app with SoundCloud to use the service (Register your app).
Another information is that Webservers where a basedir restriction is set and/or safe mode is active don't allow the CURLOPT_FOLLOWLOCATION = true option. Here is a workaround for these webservers in the Soundcloud.php file.
Related
I would like to create a campaign using Facebook API. I tried to run all available example without success.
First of all I created an App in order to have a APP_ID and a APP_SECRET.
I did all the procedure to add my Ad_account following the tutorial.
I downloaded all the SDK to facilitate Facebook API use like:
facebook-php-ads-sdk and run adgroup_creation.php and curl_log.php with my data, without success.
facebook-php-sdk-v4 I suppose it is less specific than the previous one.
Multi-Product Ads with the Facebook Marketing POST -> developers.facebook.com/ads/blog/post/2015/03/26/creating-multi-product-ads/
the developers reference -> developers.facebook.com/docs/reference/php/4.0.0
I used "Composer" to get all dependency.
In all this case I had problem to create a campaign using more or less this code:
$campaign = new \FacebookAds\Object\AdCampaign(null,"act_$ACCOUNT_ID");
$campaign->setData(array(
AdCampaignFields::NAME => 'My First Campaign',
AdCampaignFields::OBJECTIVE => AdObjectives::WEBSITE_CLICKS,
AdCampaignFields::STATUS => AdCampaign::STATUS_PAUSED ));
// PROBLEM is Here
$campaign->create();
Any help? How can I get a more useful error?
It's difficult to help without knowing the exact error. However, you could try this: before creating your campaign, initialize the API using:
Api::init(<your_app_id>, <your_ap_secret>, <your_token>);
(You need to load FacebookAds\Api to use this function).
In bigcommerce site I want functionality like anonymous users can upload image for products which he wants to purchase and add to cart.Like this (http://www.woowoonails.com/) site.
When you will open this link you will see Design Your Own Nail Wraps! container on home containing link user your own photos when you will click on this you will be on this link (http://www.woowoonails.com/designer/layout).Here you can upload your photos and click on add to bag. Same functionality I want on my site but I did not get any idea.Bigcommerce team does now allow to upload php file to their server.Then I tried to use api.
But I am not able to configure it.I have downloaded the api from (github.com/bigcommerce/bigcommerce-api-php) .But I am not getting idea how to configure it and use.
I have also download the single php file(raw.github.com/bigcommerce/bigcommerce-api-php/master/bigcommerce.php) and put it inside the Bigcommerce1 folder and then include in my file containing code:
require 'Bigcommerce1/bigcommerce.php';
BigCommerce_Api::configure(array(
'store_url' => 'siteurl',
'username' => 'admin',
'api_key' => 'df38dd10e9665a3cfa667817d78ec91ee9384bc3'
));
But nothing work.Can you give me some light about how can I achieve the functionality to upload photos and also about api configuration.
Thanks
You want to use the FTP not the BigCommerce API to capture the image... BigCommerce does support file uploading, but from what I have read it is an afterthought and is not configurable via the API. It is easier therefore to have an iframe for file upload, capturing the file contents and uploading it to the bigC (s)FTP server for storage...
This means you could post a file to any other site (so hosted externally) upload it to the FTP under some unique id, and when the order was submitted re-join the two.
Also to connect to the BigCommerce API, it is best to write or use a wrapper function library around BigCommerce
so for example we made the library object-based due to errors and undesirable functionality in the PHP version of the API, and a difference in coding styles, so we just use the following to get all orders 'Awaiting Fulfillment' and work from there...
$bcAPI = new bigcommerceAPI();
$orders = $bcAPI->getOrders();
$orders = array_filter($orders,function($data){ if($data->status == 'Awaiting Fulfillment'){ return true; } return false; });
I need a way to display videos from a specific channel on a page using PHP.
I have authenticated my app and I can use some methods using the advanced API. I am using the official vimeo PHP library to connect.
Below is what I am trying to do and when I dump the array I do not get anything. I can get info back from using get videos from the entire account method.
require_once('/url/vimeo/vimeo.php');
$vimeo = new phpVimeo('number', 'number');
$vimeo->setToken('number','numbers');
$videos = $vimeo->call('vimeo.channels.getVideos', array('ACCOUNT' => 'NAME'));
If I put the channel name where ACCOUNT is I will get an invalid signature error.
Is it worth using something like simple HTML parser for PHP and doing it that or worth sticking with the advanced API?
I would highly advise using the advanced api. If you parse the html, it will break any time vimeo changes their channel pages. Additionally, channels have more than one layout
eg: vimeohq and nicetype
The second parameter of the "call" function should be any querystring parameters the api method requires.
In the case of "vimeo.channels.getVideos" you can provide
channel_id
user_id
page
per_page
summary_response
full_response.
To experiment with the getVideos method, you can use the playground.
So in the end, I believe you want the function to look like this..
$videos = $vimeo->call('vimeo.channels.getVideos', array('channel_id' => 'NAME'));
where NAME is either the channel id, or the channel name (the channel name matches the url slug, so for example "nicetype" not "nice type"
I'm running in circle with this problem so I submit it here.
I have created a facebook fanpage and a website for my mother to promote her music. Since she is quite used to facebook I decided that instead of creating a whole backoffice, the website would simply display the fanpage's posts, photos and events. I do this with simple calls to
$data= $fb->api('/'.PAGE_ID.'/posts?fields=id');
for example (or 'notes', 'events'...). The problem is that I have to use a specific access token that I get from my own 'me/accounts/' permissions. From time to time (say every month) I have to go to the Graph API Explorer, get that token, and save it in the website config.
I'm wondering if I couldn't generate that access token server-side on my website, but I can't seem to make it happen. the facebook PHP SDK can't acces my api('/accounts') graph results unless I'm the authentified user (obviously), and a call to api(PAGE_ID.'?fields=access_token') only returns the page's ID.
What Am I doing wrong? can the facebook php sdk make api calls on my behalf (independently of users)?
More info : I created the fanpage, and a simple app called feed reader, with *manage_pages* permission. I'm the only user that authorized that app, and I don't want the user on the website to have to login (why should they? it's my fanpage, why would I need their *manage_page* permission?).
To be honest I kinda feel that public posts sould be public in the graph api too, but I'm sure there is a reason.
To be honest I kinda feel that public posts sould be public in the graph api too, but I'm sure there is a reason.
You can get to any users public posts like so:
Note: this assumes you are using the PHP SDK here http://developers.facebook.com/docs/reference/php/
$facebook = new Facebook(
array(
'appId' => 'fb_app_id',
'secret' => 'fb_secret',
)
);
$url = '/' . 'fb_username' . '/posts?fields=id,name,created_time,message,story,type&limit=10'; // you might need to screw with this some
$page = $facebook->api($url);
while(count($page['data']) > 0)
{
foreach($page['data'] as $fb_post)
{
// USE THEM DATAS
}
// Keep retrieving next pages until spent
$url_parts = parse_url($page['paging']['next']);
$url = '/' . 'fb_username' . '/posts?' . $url_parts['query'];
$page = $facebook->api($url);
}
this is an example from: https://github.com/fyaconiello/WP_Social_Network_Posts/ which pulls FB posts in and saves em as WP posts. It was written to answer a different question.
I have been investigating the Facebook Open Graph API. There is a "manage pages" extended permission which allows publishing to a user's Facebook Page news feed/wall via "impersonation". This is nice functionality, but is there anything more you can do through the API?
Specifically, I would like to be able to Add or Remove a "Tab" application from a user's Page via the API. Right now it's complicated to guide a user through the process of adding a tab app to their business (or Place) Facebook Page, and it would be AWESOME if they could just grant my app permission and I could add the app for them with the API.
Basically I am wondering if the API allows for true "page management", or just posting to the Page.
Anyone have any experience with this?
Is the best I can do pointing them to the "add.php" page with the "page" GET variable (e.g. http://www.facebook.com/add.php?api_key=xxxx&pages=1&page=xxxxxx)? This works OK for ADDING a tab application, but there is nothing at all to help them REMOVE an application from their Page so far as I know.
Thanks!
It is worth noting now, for anyone viewing this question (which is celebrating it's 1st birthday!), that Facebook significantly upgraded their API functionality back in July 2011. You can now Add, Remove, Rename, Reorder and set tabs as Default via the Open Graph API. The blog post is here:
https://developers.facebook.com/blog/post/524/
And the official documentation is here:
https://developers.facebook.com/docs/reference/api/page/#tabs
What Facebook does NOT have yet is a new API method for creating new tab apps, or for changing the tab icon. This is a big step though!
UPDATE: There is bug on the new bug tracker to follow about creating apps in the API if you want to follow it and see what they do: http://developers.facebook.com/bugs/295627350461318
There's a way to do it via the API. We finally got it to work, after many hours of sweat and tears :)
You can add a tab to a page without leaving your app. Here's a snippet of code that we used for that. We get a list of pages that a user manages, show them in a drop down and ask them to select what page they want to add our "my agent profile" tab to.
And the final product looks something like this - http://www.facebook.com/pages/Jennifer-Anderson-Real-Estate-Agent/185071901564573?sk=app_253956901293839
protected void btnAddTab_Click(object sender, EventArgs e)
{
if (ddlPage2.SelectedIndex >= 0)
{
FaceBookPages page = FaceBookPages.LookupByPageID(long.Parse(ddlPage2.SelectedValue));
if (page == null)
throw new NPlaySysException("FaceBookPages is null.");
AnalyticLog log = new AnalyticLog();
log.EventID = FBCommon.Events.AddAgentAppTabID;
log.UserID = UserID;
log.EventTime = DateTime.Now;
log.Update();
string result = FacebookSvc.AddTab(Web.AgentAppID, "me", page.AccessToken);
if (result.Equals("true"))
{
FaceBookPages.UpdateAgentProfileAdded(page.PageID, true);
List<FaceBookPages> notTabbedPages = FaceBookPages.LookupAgentProfileNotAddedByUserID(UserID);
imgStep3.ImageUrl = StepDoneImagePath;
divStep3.Attributes["class"] = StepDoneCssClass;
phStep3.Visible = false;
Step3Done = true;
btnCloseStep3.Visible = false;
if (notTabbedPages.Count > 0)
btnEditStep3.Visible = true;
else
btnEditStep3.Visible = false;
}
else
{
lblErrorAddTab.Text = "Failed to add your profile to page.";
Web.EmailError(string.Format("FacebookSvc.AddTab Failed. result={0}<br />UserID={1}<br />PageID={2}", result, UserID, page.PageID));
}
}
}
Yes, the best you can do is direct them to the add.php url. You can't do anything to help them remove the app.
The good news is that the user used to have to go through the add process AND physically decide to "enable" the tab by finding it in the tab dropdown on the page. Facebook has recently changed that and it seems that the tab is now immediately enabled after a user adds the app to their page.
As for "has_added_app" that works... sorta. It will tell you if the app is added to the page, but it won't tell you if the tab is enabled. For example, a user can disable the tab but still technically have the app installed on the page. Therefore "has_added_app" will return true even though the tab isn't actually visible.