An example of how to call admin.setRestrictionInfo from PHP SDK - facebook

This is what I got so far and the returned result is empty
$params = array(
"method"=>"admin.setRestrictionInfo",
"restriction_str"=>"{'age':'21+'}"
);
$this->fb->api($params)
According to this page
http://wiki.developers.facebook.com/index.php/Session_Secret_and_API_Methods
I need to pass the Application Secret along with this type of API call, but I can't figure it out how to do it with PHP SDK.
Any inputs, directions would be appreciate as well
Cheers

simple
$this->fb->setSession(); //set user session to null
$params = array(
"method"=>"admin.setRestrictionInfo",
"restriction_str"=>array("age"=>18+)
);
$this->fb->api($params);

Related

Passing input parameters to API

I am creating a Yii2 project. But instead of writing the logics in the controller I am trying to call APIs from the controller as described here:
yii2-call-api-method-from-backend-controllers
Can I pass input parameters to the called API ? If so pls mention how to.
Thanks in advance
To add get parameters during api call, try:
$res = Yii::$app->runAction('api/user/get_call',['a'=>'sth','b' => 'sth_else']);
To add post parameters is a bit trickier. You have to set body parameters before call:
Yii::$app->request->setBodyParams(['a' => 'sth', 'b' => 'sth_else']);
$res = Yii::$app->runAction('api/user/post_call');

Cake PHP pass parameter with form to controller

I don´t know how to securely pass a parameter via form with Cake.
The method I use now is as follows:
$this->Form->create('Post', array('label' => '', 'action' => '', 'url' => 'inseratAngenommen/'.$postId));
In the controller there stands:
function inseratAngenommen($id = null, $bs = null){
//stuff
}
The poblem is that the user can modify the output number of $postId in the browser:
action="/cakephp/posts/inseratAngenommen/149"
For that case I want to pass the parameter invisible in the HTML. Is that possible?
I thought of a method like the Form->PostLink provides. I couldn´t find anything.
Thanks in advance.
It is not possible to send an parameter securely over a website as the data is sent by the user.
Use the validation methods of cakephp to make sure the data is correct.
1] method one: add obscurity: hide the $id into a posted field by:
$this->Form->hidden('id');
$this->Form-field('id'); // even this one will do as cake hides ids by default
2] method two: keep the id on the server for instance in a session
$this->Session->write('current-edited-post-id', $id); // upon form display
$id = $this->Session->read('current-edited-post-id'); // upon form submission
but be warned thou, that method 2 doesn't behave well, if the user opens multiple tabs and operates one session from both of them :(

Facebook create an album graph api

I have written a facebook app which checks if an album exists, if it does not it creates one.
This was all working 2 weeks ago and now I go and check it to show the client and it is no longer working. I was thinking it could have something to do with Facebook and maybe they now require an SSL? I can't find any evidence of this on there website however.
The error I am getting is:
Warning: file_get_contents(https://graph.facebook.com/517578134925015/albums?access_token=AAAD5tUCp808BAIZBPk4eV11mlf9C92velLsDeZAm5mXhKZCkwpM3LNy7ax6BBmhuH4BVZBUN6Iycyt55NoXZAFSts9zHeCFNzT6FLJYucgT2SQG8fOYIP) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in /var/www/vhosts/hidden/development/cms/backend/publishAlbum.php on line 59
My current code is:
//If no album ID is set, create a new album.
$graph_url = "https://graph.facebook.com/".$pageId."/albums?" . "access_token=". $pageAccessToken;
$postdata = http_build_query(
array(
'name' => $albumName
)
);
$opts = array('http' =>
array(
'method'=> 'POST',
'header'=>
'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = json_decode(file_get_contents($graph_url, false, $context));
Any help is appreciated.
Thanks
EDIT:
The code I tried that uses the API.
$params = array(
'name' => 'testtest',
'message' => 'test test'
);
try{
$albumtResult = $facebook->api('/'.$pageId.'/albums', 'post', $params);
}
catch(FacebookApiException $e){
error_log($e);
$albumtResult = null;
}
$albumId = $albumtResult->id;
Here is the caught exception: http://pastebin.com/pxeyRTDn
Well, the reason for this error would be much easier to figure out, if you’d used the PHP SDK to make API calls, instead of doing them “by hand“ using file_get_contents … because using the SDK, you get an exception that should point to the error cause, whereas file_get_contents (by default) just throws a warning when it gets anything else than a 2xx HTTP status code for an answer, and does not let you access the response body (which will most likely contain a human-readable error message as well).
My advice: Use the SDK!
Otherwise, add to the context parameter that you want to see the returned data even if the status code signals an error. (details -> see manual)
After a lot of searching, someone created a bug report on Facebook that was almost identical to my problem.
Since being created it has had a lot of repo's and other people reporting that they are also having the same issue.
The priority on facebook has been changed to high so hopefully it gets fixed soon.
Facebook bug report: https://developers.facebook.com/bugs/376442565760536?browse=search_50361119879b15494037772
Thanks for everyones time.

query Canvas URL using FQL

It seems like http://developers.facebook.com/docs/reference/fql/application/ provides all the information except for Canvas URL. Is it possible to query this information any other way?
Well, the solution I came up with, was simply calling the old admin.getAppProperties method.
$info = $facebook->api(array(
'method' => 'admin.getAppProperties',
'properties' => array('publish_url'),
));

Zend Framework google translate usage

I'm trying to translate automatic a string using the google translator! Using Zend_Http_CLient is not able to log in in the application and retrieve the translated words. It returns to me an authentication error.
I google and searched here something about it but had no success. Can someone give a hand on it and tell me where can I find some idea on how to use Zend_Gdata with Google Translate and authenticate at the service?
Thanks a lot, best regard's.
As far as i know Zend GData classes doesn't support google translate yet
source : http://framework.zend.com/manual/en/zend.gdata.html
in the same page you would find a link to this : http://code.google.com/p/gtranslate-api-php/
i had give it a simple try and it seems to be working BUT note the comment in the class declaration
Google requires attribution for their
Language API, please see:
http://code.google.com/apis/ajaxlanguage/documentation/#Branding
hopefully that would help
please provide the error message to make your question more clear
thanks
$client = new Zend_Http_Client('http://ajax.googleapis.com/ajax/services/language/translate', array(
'maxredirects' => 0,
'timeout' => 30));
$client->setParameterGet(array(
'v' => '1.0',
'q' => 'Привет',
'langpair' => 'ru|en'
));
$response = $client->request();
$data = $response->getBody();
$server_result = json_decode($data);
$status = $server_result->responseStatus; // should be 200
$details = $server_result->responseDetails;
$result = $server_result->responseData->translatedText;
echo $result;
die;
There's no official Google Translate, yet. But this translation adapter might help:
http://www.zfsnippets.com/snippets/view/id/35
Also, if you do use this, be sure to CACHE your results! You don't want to hammer the service over and over again for the same translations.