Facebook API Search - Search for Groups? - php

I have been testing the Facebook php sdk. I am able to search for pages & places but not groups. According to the documentation, this should return groups...
https://graph.facebook.com/search?q=programming&type=group
The below code works. If I change the type from "page" to "group", the code fails. I do not get an exception:
$query = urlencode('Harlem');
$type = 'page';
$results = $facebook->api('/search?q='.$query.'&type='.$type);

It depends on what kind of Access Token you're using. As of https://developers.facebook.com/docs/reference/api/search/#access_tokens searches for pages require an App Access Token, whereas searches for Groups require an User Access Token. Please check accordingly.

Related

Facebook API : Empty Result for Ad Leads

I am building a PHP script based on Facebook Marketing API,
The API system works fine,
I can get the result for the campaigns, the ads, and full insights as well.
But, I want to get the result of the leads.
Note (1): I got admin access to the APP, the Ad account, and the page as well,
Note (2): App Status: In Development
Note (3) : I send the API request for "leads_retrieval" and "leads_retrieval",
$permissions = ['email','public_profile','leads_retrieval','ads_management', 'ads_read', 'business_management', 'read_audience_network_insights', 'read_insights', 'manage_pages', 'pages_show_list', 'pages_manage_cta','pages_manage_instant_articles', 'publish_pages', 'read_page_mailboxes'];
My Code to get the lead result :
$ad = new Ad('<AD_ID>');
$leads = $ad->getLeads();
$lead = $leads->getResponse()->getBody();
print_r($lead);
Result:
{"data":[]}
So for some reason, I still get the incorrect empty result for the leads!
Any idea about how to get the correct lead result for the Ad?
Reference : https://developers.facebook.com/docs/marketing-api/guides/lead-ads/retrieving/v2.9
I have same problem before but I found that I'm using incorrect ad_id.
double check you ad id, its possible that your not getting the full list of ad id inside adset.
use $ads->fetchAfter() to get the next page of ads
check complete code here https://stackoverflow.com/a/56500241/2588592

invalid parameter in posting offer to facebook api

I have problem with posting offer to page (which I am admin) via facebook api. It'is work, when I post feed to this page, but not for offers. This always return me FacebookSDKException with message : Invalid parameter. I use PHP (Laravel framework), but I think it does not matter on the language I use. I use this code:
try {
$response = $fb->post('/' . $page_id . '/offers' , $offerData, (string) $request->access_token
);
} catch (\Facebook\Exceptions\FacebookSDKException $e) {
return response()->json(['error'=>$e->getMessage(),
], 200);
}
where my "$request->access_token" is page access token. And in my "$offerData" I have this fields:
$offerData =[
'claim_limit'=>8,
'expiration_time'=>\Carbon\Carbon::now()->addDays(10)->toDateTimeString(),
'message'=>"bbb",
'title'=>"ascvc",
'coupon_required'=>false,
'image_url'=>'...',
'published'=>true,
'reminder_time'=>\Carbon\Carbon::now()->addDays(5)->toDateTimeString(),
// 'scheduled_publish_time'=>5
];
I also try do this by curl (not by first code) and by curl it returns similar error message.
"{"error":{"message":"Invalid parameter","type":"OAuthException","code":100,"error_subcode":1528104,"is_transient":false,"error_user_title":"Check Your Admin Permission Level","error_user_msg":"Only some admins of your Page are able to create and edit offers. Talk to the person responsible for your Page about your admin permission level.","fbtrace_id":"..."}}"
It looks that there is problem with permissions but at login to facebook I set this permissions:
['manage_pages', 'pages_show_list', 'email',
'user_hometown', 'publish_actions', 'user_photos', 'publish_pages']
I have no idea where is problem. I must to tell you that feeds on same page works fine, but not offers. Can you help me, please?
Take a look at the newer /nativeoffers endpoint; that should be a cleaner path through this one.
https://developers.facebook.com/ads/blog/post/2016/08/30/offer-ads-apis/

Soundcloud get track ID from link (PHP)

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.

Displaying a list of videos from a channel - Vimeo Advanced API

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"

reading posts from a specific fanpage

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.

Categories