I have a PHP script like:
$facebook = new Facebook( array( 'appId' => APP_ID, 'secret' => APP_SECRET ) );
$facebook->setDefaultAccessToken( ACCESS_TOKEN );
$post_comment = $facebook->api( $object_id . "/comments", "POST", array(
'source' => $facebook->fileToUpload('http://healthhub.co/wp-content/uploads/2014/02/Group-Slider.jpg'),
'message' => "Comment with photo!"
) );
Then, I checked on Facebook, it just like [result of post comment][1]
[1]: https://i.stack.imgur.com/6l5yp.png , in while, I want it like that: result wanted
I'm trying to create a new location for an existing page using an APP with Standard Access, but It's show me an error "Only white-listed APP can create new pages using this endpoint /{page_id}/locations".
Facebook SDK PHP
Facebook Graph API v2.9
My code:
$fb = new Facebook(['app_id' => app_idp,'app_secret' => app_secret,]);
$fb->setDefaultAccessToken(master_page_access_token);
$new_location['hours'] = array("mon_1_open"=> "10:00",
"mon_1_close"=>"19:00",
"tue_1_open"=> "10:00",
"tue_1_close"=> "19:00",
"wed_1_open"=>"10:00",
"wed_1_close"=> "19:00",
"thu_1_open"=> "10:00",
"thu_1_close"=> "19:00",
"fri_1_open"=> "10:00",
"fri_1_close"=> "19:00",
"sat_1_open"=>"10:00",
"sat_1_close"=>"19:00"
);
$location = array(
'hours'=>$new_location['hours'],
'location'=> array(
'street'=>$full_address,
'latitude' => $latitude,
'longitude'=> $longitude,
'city_id'=> $city_id,
'zip'=> $zip),
'phone' => $phone ,
'place_topics'=>array('210979565595898',
'199512783398620',
'108472109230615'),
'price_range' => '$$',
'store_location_descriptor' => $store_location_descriptor,
'store_name'=> $store_name,
'store_number'=> $store_id,
);
try {
$new_pages = $fb->post('/{page_id}/locations',$location,master_page_access_token);
}
catch (Exceptions\FacebookResponseException $exc) {
echo $exc->getMessage();
}
Error
enter image description here
I am developing a test for a controller function and basically it just acts upon a cake request, is there anyway to mock cake request inside the test function so that whenever the controller tries to access $this->request->data it returns the data i have set in the test case? if there is a way please tell me how.
Regards
The documentation contains an example of how to set the request data. For quick reference:
public function testIndexPostData() {
$data = array(
'Article' => array(
'user_id' => 1,
'published' => 1,
'slug' => 'new-article',
'title' => 'New Article',
'body' => 'New Body'
)
);
$result = $this->testAction(
'/articles/index',
array('data' => $data, 'method' => 'post')
);
debug($result);
}
i have written following code to learn how fql multiquery works:
include_once "fbmain.php";
try{
$your_id=xxxxxxxx;
$fql= '{
"friends":"SELECT uid2 FROM friend WHERE uid1='.$your_uid.',"
"friendinfo":"SELECT * FROM standard_user_info WHERE uid IN (SELECT uid2
FROM #friends)"
}';
$res = $facebook->api_client->fql_multiquery($fql);
}
catch(Exception $o){
d($o); // d() is function to print
}
but the output shows error
Call to a member function fql_multiquery() on a non-object on line 9
i have also tried other queries instead of these two , but the problem remains same. i am using php sdk 3.0.
help pls.
I do not use Multi Query, since fql has moved to the graph api. Instead i use batch request.
Here is a sample of a request of /feed, the comments of the 1st 10 results and fql multi of the permalink from the 1st 10 posts. I am sure this is a bit over kill for what you need but is the best example i have for mixing graph and fql and using name feature, which seems is what you need to carry friends.
https://developers.facebook.com/docs/reference/api/batch/
<?php
if($type=="home"){
$relURL = '/'.$pageid.'/'.$type.'?'.$access_token.'%26limit='.$limit.'%26return_ssl_resources=1%26fields=id,from,name,message,likes,comments,link,picture,caption,story,source,created_time,type,actions,application,object_id,description%26since='.$since.'%26until='.$until.'%26offset='.$offset.'';
}else{
$relURL = '/'.$pageid.'/'.$type.'?'.$app_access_token.'%26limit='.$limit.'%26return_ssl_resources=1%26fields=id,from,name,message,likes,comments,link,picture,caption,story,source,created_time,type,actions,application,object_id,description%26since='.$since.'%26until='.$until.'%26offset='.$offset.'';
}
$queryProfile = array(
array('method' => 'GET', 'relative_url' => '/'.$pageid.'?fields=id,name,link,picture%26'.$app_access_token.''),
array('method' => 'GET', 'relative_url' => ''.$relURL.'', 'name' => 'comments', 'omit_response_on_success' => false),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.0.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.1.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.2.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.3.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.4.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.5.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.6.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.7.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.8.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.9.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.0.id}\''),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.1.id}\''),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.2.id}\''),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.3.id}\''),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.4.id}\''),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.5.id}\''),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.6.id}\''),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.7.id}\''),
//array('method' => 'GET', 'relative_url' => '/'.$pageInfo[id].'/photos?fields=id,name%26limit=9')
);
$batchResponse = $facebook->api('?batch='.json_encode($queryProfile), 'POST');
$pageInfo = json_decode($batchResponse[0]['body'], true);
$pageType = $pageInfo[type];
$pageLink = $pageInfo[link];
$thispageid = $pageInfo[id];
$MEcomments = json_decode($batchResponse[1]['body'], true);
?>
Looks rather a problem with the instantiation of
$facebook->api_client
Worth to note also that in [standard_user_info] the column [uid] is of type string so you would probably also need to add quotes.
https://developers.facebook.com/docs/reference/fql/standard_user_info/
According to FB docs, FQL multiquery should be faster than subsequent batch calls.
https://developers.facebook.com/docs/reference/fql/
i can do it via url:
https://api.facebook.com/method/notifications.sendEmail?recipients=ID_USER&subject=test&text=test&access_token=USER_ACCESS_TOKEN
http://developers.facebook.com/docs/reference/api/message/
EDIT:
I see now you are trying to use the PHP SDK. Perhaps something like the following will work for you (saw this on another stackoverflow question):
$parameters = array(
'app_id' => $facebook->getAppId(),
'to' => $facebookUserId,
'link' => '(required) The link to send in the message. (??)',
'redirect_uri' => 'URL_TO_REDIRECT_TO_AFTER_USER_CLICKS_SEND_OR_CANCEL',
'picture' => 'OPTIONAL_URL_TO_IMG--AUTOGENERATED BY LINK',
'name' => 'OPTIONAL_NAME_OF_MESSAGE/ARTICLE--AUTOGENERATED BY LINK',
'description' => 'OPTIONAL_DESCRIPTION_TEXT--AUTOGENERATED BY LINK'
);
$url = 'http://www.facebook.com/dialog/send?'.http_build_query($parameters);
echo '<script type="text/javascript">window.open('.json_encode($url).', "_blank", options, false);</script>';