Facebook PHP SDK (latest - 16.1.13) & Access Token [closed] - php

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have the following code:
public function get_facebook()
{
$loginUrl = Helpers::fbLogin();
if(Input::get('error'))
{
Session::flash('failure', 'You need to give permissions.');
return Redirect::to('signup');
}
else
{
$facebook = IoC::resolve('facebook-sdk');
$uid = $facebook->getUser();
$fbuser = $facebook->api('/me', 'GET');
$user = User::where('uid', '=', $uid)->or_where('email', '=', $fbuser['email'])->first();
if(is_null($user)){
Session::flash('fbuser', $fbuser);
return Redirect::to('signup');
} else {
Auth::login($user);
return Redirect::to('/');
}
}
return Redirect::to($loginUrl);
}
But I get this message:
An active access token must be used to query information about the current user.
Also when I print the $facebook->getAccessToken() & try opening my app with different facebook accounts I get same token.
What is access token & what do we use it for?
P.S. I have set up properly my appID & secret code. The problem is that sometimes it works, sometimes it doesn't.

Access token is token, that is given to your application by user to access his/her information from your application. In order to get that token, user has to give you permission to access at least his basic information.
More here

Related

Custom error message for input [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I'm trying to set a custom message for an input:
$this->form_validation->set_message('username', 'Choose a business, Mang!');
and display this:
<?php echo form_error('username'); ?>
But nothing displays for me, what is wrong?
Is this what I need? Example:
if($result)
{
$this->form_validation->set_message('username', 'Choose a business, Mang!');
}
You need to set rules as such:
$this->form_validation->set_rules('form_field_username', 'username', 'required|callback_business_check');
function business_check($username) {
if(strlen($this->input->post('form_field_business')) == 0) {
$this->form_validation->set_message('business_check', 'Choose a business, Mang!');
return false;
}
return true;
}
This is providing I have the right idea of what you are doing...

Adding an else statement to page count? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a page count to limit the number of times a logged out user can view profiles. If a user is logged out they are redirected to a sign-up page, this is right and should be what's happening but i'm getting the same thing happen when the user is logged in, how can i add an else statement or if statement to say only redirect to sign up page or only limit profile hits if not logged in?
Thanks
<?
!session_id() ? session_start() : null;
verify_profile_visit_limit();
function verify_profile_visit_limit(){
$free_profiles = array(99999,99998,99997,99996,99995,99994,99993);
if(in_array($_GET["id"], $free_profiles)) return;
if(! isset($_SESSION["page_access_count"])){
$_SESSION["page_access_count"] = 1;
}
$_SESSION["page_access_count"]++;
if($_SESSION["page_access_count"] > 5){
header("Location: limit.php");
exit();
}
}
?>
Just add an OR condition so you return if the user is logged in:
if(in_array($_GET["id"], $free_profiles) || isset($_SESSION['loggedIn']) && $_SESSION['loggedIn']) return;
With that your function will return before running the limit check. Assuming you store a boolean (true/false) in $_SESSION['loggedIn'].

How to get latest Tweets of an User [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am trying to get my client latest tweets. After Searching in Google i got some code. Unfortunately the code is working in localhost, But not working in the Hosting server. Its saying couldn't find the server. I am posting the code snapshot..
<?php
function getTwitterStatus($userid){
$url = "http://twitter.com/statuses/user_timeline/$userid.xml?count=1";
$xml = simplexml_load_file($url) or die("could not connect");
foreach($xml->status as $status){
$text = $status->text;
}
echo $text;
}
//my user id AmitEducation
getTwitterStatus("AmitEducation");
?>
Please help me out. If anyone have better suggestion please help me.
Use the Twitter Search API, it's really awesome. And it's JSON. [+1]
$tweets = json_decode(file_get_contents("http://search.twitter.com/search.json?q=php&rpp=5&include_entities=true&result_type=mixed"));
foreach($tweets->results as $t){
echo "Username: {$t->from_user_name}";
echo "Tweet: {$t->text}" . PHP_EOL;
}
Please read the documentation for how to use and see examples.
change the username in the link
<?php
$json = file_get_contents("http://twitter.com/status/user_timeline/username.json?count=10", true); //getting the file content
$decode = json_decode($json, true); //getting the file content as array
print_r($decode);
?>

How can I use $_GET in the same page [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
My pseudo code is as follows:
if($_GET['action'] == 'list'){
do function getFileList($dir)
else
do nothing
exit;
}
require_once "./dir.php";
require_once "./echo.php";
function getFileList($dir)
{
}
Your psuedo code is almost there.
require_once "./dir.php";
require_once "./echo.php";
function getFileList($dir)
{
/* ... */
}
if($_GET['action'] == 'list') {
getFileList($dir);
}
Are you asking how to send a variable via GET to a PHP file from within the same PHP file? You can create a form that submits to itself: http://www.tellingmachine.com/post/Simple-self-submitting-PHP-forms.aspx.
If you are looking to do something else, please provide additional details.

Automatic logged out [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a php page from where my users log-in to the application. It is working fine.
Yesterday, all of a sudden the users were able to login but were forced out and redirected to the login page again.
My database has logged in the user's login timings and this problem was automatically solved after about 2 hours.
Why will like this happen?
In the following code it will check for the session value and if it is not found then redirect to the error page.
Yesterday, it was redirecting to error page even if the session value was set.
<?php
if($_SESSION['ucd']<>"" && $_SESSION['sid']<>"" && $_SESSION['sid']<>0)
{
$query="select count(*) from active_sessions where user_cd='".$_SESSION['ucd']."'
and session_no='".$_SESSION['sid']."' and START_TM like DATE_FORMAT(now(),'%Y-%m-%d%')";
//echo $query;
$cnt=$dbop->select($query);
if($cnt[0] == '0')
{
$sender = "sender=".urlencode($_SERVER['PHP_SELF']);
session_unset();
header("Location:../login/error.html?$sender");
die;
}
else{
$query = "update active_sessions set LAST_ACTIVITY = NOW() WHERE SESSION_NO = ".$_SESSION['sid'];
mysql_query($query);
?>
<?php
}
}
else
{
$sender = "sender=".urlencode($_SERVER['PHP_SELF']);
session_unset();
header("Location:../login/error.html?$sender");
die;
}
?>
I don't see session_start() anywhere in your code.

Categories