trying to get every post and comment from a facebook page, I made this function that should go through the pagination:
$req = $facebook->api("/" . $pagename . "/?fields=posts.fields(message,link,created_time,shares,likes,comments)");
function parcours_arbre($ab)
{
GLOBAL $facebook;
GLOBAL $pagename;
$next = create_request($ab['posts']['paging']['next']);
$next_req = $facebook->api($pagename.$next);
$ab_next = $next_req['data'];
$prev = create_request($ab['posts']['paging']['previous']);
$prev_req = $facebook->api($prev);
$ab_prev = $prev_req['data'];
if (empty($ab)) {
display_results($ab['posts']['data']);
} else {
parcours_arbre($ab_next);
parcours_arbre($ab_prev);
}
}
I unfortunately get the following error:
Notice: Undefined index: posts in /form.php on line 36
Notice: Undefined offset: 3 in /utils.php on line 20
Notice: Undefined offset: 4 in /utils.php on line 20
Fatal error: Uncaught GraphMethodException: Unsupported get request. thrown in /sdk/src/base_facebook.php on line 1271
Any idea how i could avoid it or what is going on? Would this go away if i use the "until" statement in my api request?
Thanks a lot,
To explain each error
the variable $ab which is an argument to the function, does not have a "posts" index. You should try to var_dump this variable so you can see what it actually looks like.
same as above
same as above
the api function takes 3. The path which should just be #pagename. The method ("GET" or "POST") most likely POST because GET is causing an error. The parameters, which should be array("fields" => "posts.fields(message,link,created_time,shares,likes,comments)")
I noticed that for next you have the code
$next_req = $facebook->api($pagename.$next);
but for previous you have
$prev_req = $facebook->api($prev);
Might want to look into this.
Related
Not sure if this is an Wordnik API issue or just a php error on my part. Here is my current code:
require('./wordnik/Swagger.php');
require('./wordnik/WordsApi.php');
$myAPIKey = '00144cdc1140c4192780f08c3f608399234240dcb560d3e4b';
$client = new APIClient($myAPIKey, 'http://api.wordnik.com/v4');
$wordApi = new WordApi($client);
$input = new WordObject();
$input->includePartOfSpeech='noun';
$input->excludePartOfSpeech='affix,article,connjunction,preposition,abbreviation,suffix';
$input->hasDictionaryDef='true';
$input->minCorpusCount='10000';
$input->maxCorpusCount='null';
$input->minDictionaryCount='20';
$input->maxDictionaryCount=null;
$input->minLength='4';
$input->maxLength='20';
$random_word = $wordApi->getRandomWord($input); //THIS IS THE ERROR LINE
print $random_word->text;
and here is the error I get:
Fatal error: Call to undefined method WordApi::getRandomWord()
Any help is greatly appreciated. The error is happening on that line towards the bottom, just not sure why. Thank you.
getRandomWord() is defined in WordsApi (plural words).
You have: WordApi
You need: WordsApi
I'm getting this error and after checking for similar errors I verified the syntax is correct. The complete error is;
WRITE OK
READ OK
Notice: Undefined variable: dbRead in C:\vhosts\phpcs5\lesson07\workfiles\scripts\user_registration.php on line 28
Fatal error: Call to a member function quoteInto() on a non-object in C:\vhosts\phpcs5\lesson07\workfiles\scripts\user_registration.php on line 28
My connection is defined as:
$dbwrite = new Zend_Db_Adapter_Pdo_Mysql($write);
$dbread = new Zend_Db_Adapter_Pdo_Mysql($read);
I did a test first to make sure it can see the database which is what the Write OK and Read OK are as follows;
if ($dbwrite->getConnection()) {
echo 'WRITE OK<br/>';
}
if ($dbread->getConnection()) {
echo 'READ OK';
}
So I'm not sure why I'm getting this error.
dbRead is undefined. You've defined $dbread. Note the capitalization.
Look through your code base (particularly user_registration.php line 28) and switch all instances to one or the other.
So I have been working on a school project and have gotten this code for a website to work sometimes but other times it returns the error:
Notice: Trying to get property of non-object in C:\xampp\htdocs\schoolproj\getdata.php on line 27
Notice: Trying to get property of non-object in C:\xampp\htdocs\schoolproj\getdata.php on line 27
Ask
Notice: Trying to get property of non-object in C:\xampp\htdocs\schoolproj\getdata.php on line 39
Notice: Trying to get property of non-object in C:\xampp\htdocs\schoolproj\getdata.php on line 39
for the php code:
<html>
<body>
<?php echo $_POST['name']; ?>!<br>
<?php
$endpoint = "http://query.yahooapis.com/v1/public/yql";
$ticker = "'".$_POST["ticker"]."'";
$query = urlencode("env 'store://datatables.org/alltableswithkeys';select * from yahoo.finance.quotes where symbol in (".$ticker.")");
$ch = curl_init($endpoint.'?q='.$query. '&format=json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
if (curl_error($ch)){
die(curl_error($ch));
}
curl_close($ch);
//echo'<pre>';
$result = json_decode($result);
$symbol = $result->query->results->quote->symbol;
print_r($symbol);
?>
Ask
<?php
$Ask = $result->query->results->quote->Ask;
print_r($Ask);
?>
</body>
</html>
I was wondering if anyone had some advice as to how I could permanently fix the problem or have some sort of error handling. I am new to this so any help would be great. Thanks!
The problematic lines if the code you gave is the whole getdata.php file are:
l.27: $symbol = $result->query->results->quote->symbol;
l.39: $Ask = $result->query->results->quote->Ask;
And the error is telling you that at one point in this your are accessing a property of something that is not an object.
Considering you are saying it sometimes work and sometimes doesn't, it's likely that there are occasional errors, either in your query (depending on your input) or with datatables.org (see this old question on developer.yahoo which indicates that queries would fail when datatables.org doesn't respond).
Then if there is an error, the json you receive will have a structure like below (this is an error I got initially when trying your code because I had forgottent to enclose the ticker in quotes).
{
"error": {
"lang":"en-US",
"description":"Query syntax error(s) [line 1:95 mismatched input 'in' expecting ISNOTNULL]"
}
}
In this result you don't have the query attribute and thus is fails when you try to access it. You should then first check if there is an error (looking for the error attribute), and only if there is none try and access the query results.
To check for the error, you could use something like
if (property_exists($result, "error")) {
// your error handling
} else {
// your current code accessing the results
}
so I tried using https://github.com/abraham/twitteroauth/blob/master/twitteroauth/twitteroauth.php
and sometimes I get :
Notice: Undefined index: oauth_token in /myweb/twitteroauth/twitteroauth.php on line 80
Notice: Undefined index: oauth_token_secret in /myweb/twitteroauth/twitteroauth.php on line 80
but sometimes it just run (confused ??)
the code in the twitteroauth.php line 80 :
function getRequestToken($oauth_callback) {
$parameters = array();
$parameters['oauth_callback'] = $oauth_callback;
$request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
$token = OAuthUtil::parse_parameters($request);
$this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
//exit(print_r($request));
return $token;
}
so as u can see above I tried
exit(print_r($request));
the result was sometimes :
1
(error notice occurred)
and sometimes :
oauth_token=KzpRdIBm8inptvd3Xi254QUEsdf4f5eyO1XZyjW7xVU&oauth_token_secret=lmNl1rnBmR6palxHmufartersd0ivLabi5k&oauth_callback_confirmed=true1
(no error notice)
this is making me insane, can someone tell me what is the problem here ?
I tried looking at this thread : twitter oauth :geting undefined index: oauth_token_secret in
but doesn't help me :(
Thanks in advance !!
strange, it is working ok now, maybe it was my internet connection that have a problem =/
I want get from database table row name but in it i get error. ($query->code_airline => is other query as select from database table row)
code:
<?=$this->db->get_where('ticket_code', array( 'code' => $query->code_airline ))->row()->name?>
error:
A PHP Error was encountered Severity: Notice Message: Trying
to get property of non-object Filename: core/Loader.php(679) :
eval()'d code Line Number: 48
If want use it as:
<?php //This is line 49
$ca = echo $query->code_airline;
$query_tc = $this->db->get_where('ticket_code', array( 'code' => $ca ))->row();
echo $query_tc->name;
?>
have this error:
Parse error: syntax error, unexpected T_ECHO in
D:\xampp\htdocs\system\core\Loader.php(679) : eval()'d code on line 49
How can fix it?
Update:
i use as:
<?php
$ca = $query->code_airline;
$query_tc = $this->db->get_where('ticket_code',array('code'=>$ca));
$row = $query_tc->row(); //This is line 52
echo $row->name;
?>
i have this error with above php code:
A PHP Error was encountered Severity: Notice Message: Trying
to get property of non-object Filename: core/Loader.php(679) :
eval()'d code Line Number: 52
You don't ECHO in a variable assignment
$ca = $query->code_airline; //no echo here!
Also, I believe you're doing something wrong in calling $query->code_airline, but you didn't provide your code so I'm just guessing.
Suggestion: chaining is a nice feature but can be confusing, especially if written as one-liner. First of all, write it in full, you can "compact" your code later if you feel so; keep in mind readability and maintenability also:
$query_tc = $this->db->get_where('ticket_code',array('code'=>$ca));
// $ca is the value assigned above. Make sure you're calling $query->code_airline correctly, as per my suggestion.
$row = $query_tc->row();
echo $row->name;
UPDATE:
you might want to be sure that there are actually any result.
$query_tc = $this->db->get_where('ticket_code',array('code'=>$ca));
// $ca is the value assigned above. Make sure you're calling $query->code_airline correctly, as per my suggestion.
if ($query_tc->num_rows() > 0)
{
$row = $query_tc->row();
echo $row->name;
}
else
{
//do something else
}