Delete pictures from Facebook using CURL - php

I have a Facebook app, where I want to delete some pictures. I have the pictureid and access_token, and have tried every methods I have found on this site, but I get errors every time.
How can this be deleted with CURL? I've started with this:
$ch = curl_init();
$url = 'https://graph.facebook.com/'.$uid.'/photos?access_token='.$access_token;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
echo $data = curl_exec($ch);

Applications can now delete Photos - created by that application.
I tried it with a photo uploaded to a page and deleted it with its id via the Graph API Explorer
The curl url would be:
https://graph.facebook.com/'.$imageId.'?method=DELETE&access_token='.$token

Facebook does not permit applications to delete photos at all.

Related

Can't get the authorization code of Quickbooks API through curl but it works through the url

I just want to get the authorization code to obtain the access token to make API requests, I did the step manaully through the pasting the link in the browser and it works.
but through Curl PHP doesn't work I get empty string of size 1400 char.
this's the sample on Quickbooks API doc
curl -X POST 'https://appcenter.intuit.com/connect/oauth2?
client_id=Q3ylJatCvnkYqVKLmkxxxxxxxxxxxxxxxkYB36b5mws7HkKUEv9aI&response_type=code&
scope=com.intuit.quickbooks.accounting&
redirect_uri=https://www.mydemoapp.com/oauth-redirect&
state=security_token%3D138r5719ru3e1%26url%3Dhttps://www.mydemoapp.com/oauth-redirect'
Quickbooks API Auth code ref
I Turned to Curl PHP with replacing my credentials, when I visit the link I get the auth code and I could obtian the access token but can't do it in the back-end
the dir of the page that I want to get the auth code in is https://roifelawgroup.com/clientform/login/info_submit.php
but the redirect link just : https://roifelawgroup.com/ with login creds is this could be the problem?
However I tried with the same page redirect link didn't work
function authcode(){
$url = "https://appcenter.intuit.com/connect/oauth2?client_id=ABfQBA8VYPPUETO5isi2v8p39lQwEsw1ozL7NhZxxxxxx&response_type=code&scope=com.intuit.quickbooks.payment&redirect_uri=https://roifelawgroup.com&state=security_token%3D138r5719ru3e1%26url%3Dhttps://roifelawgroup.com";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // if removed this line I get 301 permanently moved
$headers = array(
"Content-Length: 0",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
}

YouTube v3 API call for search.list: proper curl setting

I am sending a call to the YouTube API using search.list (retrieve the first search result for a keyword) but I am getting nothing in return.
Here is my call:
$api_url = 'https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&type=video&key=MYKEY&&format=json&q=SEARCHTERMS;
Note: MYKEY is my API key I got from Google (currently active) and SEARCHTERMS is any word to search.
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response);
$value = json_decode(json_encode($data), true);
echo $value;
The URL works correctly (tested on browser) and I'm not getting any kind of error (console), but still this curl request isn't echoing any data from YouTube. Isn't it properly set?
P.s. My quota isn't exceeded.
SOLVED!
Watch out: youtube API doesn't read spaces in url (eg. in search terms), so you gotta streplace all of them with "+"

Facebook SDK - publish post with external image

I am having hard time publishing external image to post. I am using PHP language and curl. I would like to post image (e.g. https://cdn.pixabay.com/photo/2015/06/19/17/58/sample-815141_1280.jpg) to facebook, but the only thing which get's posted is message without any image.
The problem with using photo api is that the post is posted as a picture and not as a post containing image. How can I accomplish this? I also tried with official PHP SDK but so far no luck.
$data['message'] = $_POST["content"];
$data['access_token'] = $page_access_token;
$post_url = 'https://graph.facebook.com/'.$page_id.'/feed';
if($_POST["picture"]!==""){
$data_post['url']=$_POST["picture"];
}
if($_POST["content"]!=="")
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch);
}

Facebook Hashtag feed PHP cURL

How to get the Facebook hashtag feeds using the Facebook Graph API ? I want to get all the posts of a particular #HashTag.
I tried the below code:
<?php
$keyword = '#TagName';
$graph_url = "https://graph.facebook.com/search?type=post&access_token=xxx&q=$keyword";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $graph_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);
?>
But it returns an error :
string(82) "{" error":{"message":"No node specified","type":"GraphMethodException","code":100}}"
permission granted : read_stream
any solution for this? thank you
You cannot retrieve the hashtag feed using the API, unless you are using Facebook Trending API (which you will not get access)
https://developers.facebook.com/docs/graph-api/reference/v2.3/hashtag

How can I Delete Photo On facebook Pages via PHP SDK?

I have a problem .
I want to delete photos on facebook page , photos are sending via php sdk.
Im try all but not work..
$Curl_Session = curl_init('https://graph.facebook.com/[photoid]');
curl_setopt ($Curl_Session, CURLOPT_POST, 1);
curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, "method=DELETE&access_token=$token");
curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($Curl_Session, CURLOPT_RETURNTRANSFER, 1);
echo $a8=curl_exec ($Curl_Session);
curl_close ($Curl_Session);
Dont work..
$url = 'https://graph.facebook.com/'.$id.'?method=DELETE&access_token='.$token;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
echo $data = curl_exec($ch);
This code is dont work
$sonuc=file_get_contents("https://graph.facebook.com/".$id."?method=DELETE\&access_token=".$token);
Please Help..
Facebook allowed deleting photos if sending via php sdk.
But all codes not work ..
First off, the photo you're trying to delete must have been uploaded by the app that's trying to delete it. This is mentioned in the Facebook Documentation: A photo can only be removed by the same app that published it.
You'll need a valid Page Access Token to delete the photo too. You can get this my adding the manage_pages permission and calling /me/accounts to get the list of access tokens, finding the one for the correct page).
Finally, calling: https://graph.facebook.com/{PHOTO_ID}?access_token={PAGE_ACCESS_TOKEN}&method=DELETE will delete the photo if the app has permission, otherwise you'll receive a error like:
{
"error": {
"message": "(#200) Permissions error",
"type": "OAuthException",
"code": 200
}
}

Categories