Facebook Graph API,扩展权限(Facebook Graph API, extended permissions)
我正在尝试使用facebook Graph API来更新用户staus消息。
我在使用它时遇到以下错误,我认为新的图形sdk没有被正确引用?
Notice: Undefined property: Facebook::$api_client in /users/home/aafhe7vh/web/public/update.php on line 9 Fatal error: Call to a member function users_hasAppPermission() on a non-object in /users/home/aafhe7vh/web/public/update.php on line 9
这是我正在使用的文件http://github.com/facebook/php-sdk/blob/master/src/facebook.php
以下是我的update.php的内容:
# <?php include_once ('facebook.php'); $api_key = '@@@@@@@@@@@@@@@@@@@2'; $secret = '$$$$$$$$$$$$$$$$$$$$44'; global $facebook; $facebook = new Facebook($api_key, $secret); # include_once("config.php"); # if (!$facebook->api_client->users_hasAppPermission("status_update")){ # echo '<fb:prompt-permission perms="status_update" next_fbjs="greet()">Let us update your status </fb:prompt-permission>'; # $visibility = "none"; # } # else # $visibility = "block"; # # if(isset($_POST['hello'])) # { # $facebook->api_client->users_setStatus($_POST['hello']); # echo "<p>Your status has been updated</p>"; # } # ?> # <div id="statusdiv" style="display:<?=$visibility;?>;"> # <form method="POST"> # Please update your status:<br/> # <input type="text" name="status" /> <br/> # <input type="submit" value="change status" /> # </form> # </div> # # <script> # function greet() # { # var session = "<?=$facebook->api_client->session_key;?>"; # document.getElementById("statusdiv").setStyle("display","block"); # new Dialog().showMessage("Info","Thank you for granting us this permission! "); # } </script>
我在这里使用了上面的代码, http://fbcookbook.ofhas.in/tag/extended-permission/
我不确定config.php应该包含什么,所以我在代码中删除了该行。
谢谢。
I am trying to use facebook Graph API, to update a users staus message.
I am getting the following error while using it, I think the new graph sdk is not being properly referenced ?
Notice: Undefined property: Facebook::$api_client in /users/home/aafhe7vh/web/public/update.php on line 9 Fatal error: Call to a member function users_hasAppPermission() on a non-object in /users/home/aafhe7vh/web/public/update.php on line 9
This is the file I am using http://github.com/facebook/php-sdk/blob/master/src/facebook.php
Following is the content of my update.php:
# <?php include_once ('facebook.php'); $api_key = '@@@@@@@@@@@@@@@@@@@2'; $secret = '$$$$$$$$$$$$$$$$$$$$44'; global $facebook; $facebook = new Facebook($api_key, $secret); # include_once("config.php"); # if (!$facebook->api_client->users_hasAppPermission("status_update")){ # echo '<fb:prompt-permission perms="status_update" next_fbjs="greet()">Let us update your status </fb:prompt-permission>'; # $visibility = "none"; # } # else # $visibility = "block"; # # if(isset($_POST['hello'])) # { # $facebook->api_client->users_setStatus($_POST['hello']); # echo "<p>Your status has been updated</p>"; # } # ?> # <div id="statusdiv" style="display:<?=$visibility;?>;"> # <form method="POST"> # Please update your status:<br/> # <input type="text" name="status" /> <br/> # <input type="submit" value="change status" /> # </form> # </div> # # <script> # function greet() # { # var session = "<?=$facebook->api_client->session_key;?>"; # document.getElementById("statusdiv").setStyle("display","block"); # new Dialog().showMessage("Info","Thank you for granting us this permission! "); # } </script>
I used the above code from here , http://fbcookbook.ofhas.in/tag/extended-permission/
I am not sure what the config.php should contain so I have removed that line in my code.
Thanks.
原文:https://stackoverflow.com/questions/3112745
最满意答案
好吧,实际上我在我正在进行的项目中的BaseController中做了类似的事情:
public function smart_response($data, $redirect_to_route = null, $route_params = array()) { if (Request::ajax()) { return Response::json($data); } else { Alert::boolean($data['msg'], $data['success']); return is_null($redirect_to_route) ? Redirect::back() : Redirect::to_route($redirect_to_route, $route_params); } }
我想你可以得到我的想法。
也许你也可以使用后期过滤器? 但我认为没有正确或错误的解决方案。
Well, in fact I did something similar in the BaseController in the project I'm working on:
public function smart_response($data, $redirect_to_route = null, $route_params = array()) { if (Request::ajax()) { return Response::json($data); } else { Alert::boolean($data['msg'], $data['success']); return is_null($redirect_to_route) ? Redirect::back() : Redirect::to_route($redirect_to_route, $route_params); } }
I guess you can get my idea.
Maybe you could use a post filter too? But I don't think there is a right or wrong solution for this.
相关问答
更多-
设计一个RESTful API(Designing a RESTful API)[2024-04-17]
我正在创业,我几乎有同样的问题需要解决。 我认为唯一的区别在于第一个问题,因为我决定仅将API访问权限限于经过身份验证的用户。 但是,这是我如何解决我的问题: 1.如何使我的API安全? 正如我写的,我仅将API访问权限限于已通过身份验证的用户。 我使用基于令牌的身份验证和基于以下软件包的自己的REST注册/身份验证API端点: Django的休息框架 Django的allauth 如果你想使用这个解决方案,我建议你也看一下django-rest-auth 。 2.如何使我的API快速高效? 如果您的“请求 ... -
好吧,实际上我在我正在进行的项目中的BaseController中做了类似的事情: public function smart_response($data, $redirect_to_route = null, $route_params = array()) { if (Request::ajax()) { return Response::json($data); } else { Alert::boolean($d ...
-
对例外的回应 您可以通过处理App\Exceptions\Handler的异常来完成此操作。 你可以在render方法中使用它,喜欢: /** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ public function render ...
-
根据Laravel错误日志,您的csrf令牌不匹配。 如果您正在构建API,您可能不希望使用“web”中间件。 该中间件组正在启动会话,并将检查所有未使用READ(GET,HEAD,OPTIONS)HTTP方法的请求上的csrf令牌。 默认情况下,Laravel会将routes.php中的所有路由放入路由组中,并在app\Providers中的RouteServiceProvider中加载“web”中间件(如果版本> = 5.2.27)。 根据Laravel错误日志,这可能就是从哪里开始的。 这可能会有所帮 ...
-
是的,你可以使用这种方法: if( $request->wantsJson()){ return response()->json(['your response as json']) }else{ return view('....') } Yes you can using this approach: if( $request->wantsJson()){ return response()->json(['your response as json']) }else{ ...
-
请始终使用中间件,并在API组列表中提及apis列表,如下所示 Route::group(['middleware' => 'auth:api'], function () { Route::get('getUser','Testcontroller@getData'); }); Always go with the middleware and mention the list of apis in the API group list as follows Route::group(['midd ...
-
从你的问题,我得到以下内容: 我如何处理auth中间件...... 好吧,我们假设您有两个中间件auth.basic , auth.admin 然后你可以让你的路线像: Route::post('/api/getResponse', ['middleware' => 'auth', function () { $var = "you have access to this route"; return json_encode($var); }]); 在这里,您设置是否以及谁有权访问此特定路 ...
-
我正在研究在Google的类似项目中使用流星的可行性分析,我认为Meteor对您的项目会很好。 管理员用户创建 - 检查休斯敦 REST API - [你自己的工具不需要一个](需要用流星术语思考)。 流星有一个更简单的机制 - Meteor.call和Meteor.methods 。 用户权限 - 请参阅角色包 文件处理 - 请参阅CollectionFS或搜索大气上传 。 外部API调用 - HTTP.get使其变得微不足道。 另请参阅特定包装的气氛。 大数据表格 - 查看关于表格小部件的答案 I'm ...
-
无法直接重新排列数组,列表。 您可以创建一个包含数组和列表作为成员的类,并可以返回该类的对象。 注意:REST无法返回Array或List Retruning of Array,List is not possible directly. You can create a class with array and list as member and can return object of that class. N.B: REST cannot return Array or List
-
使用RESTful API(Work with RESTful API)[2022-07-05]
如果客户端用于通过POST调用服务器(即HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");在android中)那么你将获得用户在$_POST发布的所有数据$_POST 如果你是初学者关于休息时间,请不要在这个级别搞乱数据库,只需创建页面 并从客户端调用它,你会得到更多的路径:) if client is using to call server ...