Here's my code:
try {
if (!isset($_SESSION['E_TOKEN'])) {
$oauth_data = $oauth_handler->authorize($key, $secret, $callback);
$token = $oauth_data['oauth_token'];
$_SESSION['E_TOKEN'] = $token;
}
else
$token = $_SESSION['E_TOKEN'];
$reason = $_GET['reason'];
$client = new \Evernote\Client(array('token' => $token, 'sandbox' => true));
$advancedClient = $client->getAdvancedClient();
switch ($reason) {
case 'update':
$noteGuid = $_GET['guid'];
$noteStore = $advancedClient->getNoteStore();
$note = $noteStore->getNoteContent(array('token' => $token), $noteGuid, true, false, false, false);
}
} catch (Evernote\Exception\AuthorizationDeniedException $e) {
//If the user decline the authorization, an exception is thrown.
echo "Declined";
}
Here's the exception:
[Sat Apr 30 10:44:55.256042 2016] [:error] [pid 27190:tid 139957362468608] [client 216.104.244.35:32700] PHP Warning: strlen() expects parameter 1 to be string, array given in /usr/local/apache2/htdocs/vendor/evernote/evernote-cloud-sdk-php/src/Thrift/StringFunc/Core.php on line 36
[Sat Apr 30 10:44:55.599976 2016] [:error] [pid 27190:tid 139957362468608] [client 216.104.244.35:32700] PHP Fatal error: Uncaught exception 'EDAM\Error\EDAMUserException' in /usr/local/apache2/htdocs/vendor/evernote/evernote-cloud-sdk-php/src/EDAM/UserStore/UserStore.php:3202\nStack trace:\n#0 /usr/local/apache2/htdocs/vendor/evernote/evernote-cloud-sdk-php/src/EDAM/UserStore/UserStore.php(717): EDAM\UserStore\UserStore_getNoteStoreUrl_result->read(Object(Thrift\Protocol\TBinaryProtocol))\n#1 /usr/local/apache2/htdocs/vendor/evernote/evernote-cloud-sdk-php/src/EDAM/UserStore/UserStore.php(678): EDAM\UserStore\UserStoreClient->recv_getNoteStoreUrl()\n#2 [internal function]: EDAM\UserStore\UserStoreClient->getNoteStoreUrl(Array)\n#3 /usr/local/apache2/htdocs/vendor/evernote/evernote-cloud-sdk-php/src/Evernote/Store/Store.php(38): call_user_func_array(Array, Array)\n#4 /usr/local/apache2/htdocs/vendor/evernote/evernote-cloud-sdk-php/src/Evernote/AdvancedClient.php(69): Evernote\Store\Store->__call('getNoteStoreUrl', Array)\n#5 /usr/local/apache2/htdocs/vendor/evernote/evernote-cloud-sdk-php/src/Evernote/AdvancedClient.php(69): Evernote\S in /usr/local/apache2/htdocs/vendor/evernote/evernote-cloud-sdk-php/src/EDAM/UserStore/UserStore.php on line 3202
Note the error log entry for Core.php at line 36 expecting a string instead of an array.
Any suggestions?
I am trying to build a log parser using the zLib functions, and am running into a problem. This is my code:
$filename = '/Users/awallace/AccessLogs/access.log.6.gz';
$handle = gzopen( $filename, 'r');
while ( $buffer = gzgets( $handle, 2048 ) )
{
if ( strpos($buffer, "Leadbuilder.") !== false )
{
print $buffer . "\n";
}
gzclose($handle);
}
(I have removed error checking code). WhenI run this, I get a warning:
Warning: gzgets(): 5 is not a valid stream resource in /Users/awallace/test.php on line 22
If I dump out the handle after gzopen, I get: "Resource id #5". Any idea why this isn't working?
PHP v:5.5.29
MacOS 10.10.5
Ouput of "file" command:
/Users/awallace/AccessLogs/access.log.6.gz: gzip compressed data, from
Unix, last modified: Wed Feb 24 23:35:20 2016
Thanks..
You close the handle inside your loop, so on the second loop iteration $handle is invalid.
Instead do this:
$handle = gzopen( $filename, 'r');
while ( !gzeof($handle) )
{
$buffer = gzgets( $handle, 2048 );
if ( strpos($buffer, "Leadbuilder.") !== false )
{
print $buffer . "\n";
}
}
gzclose($handle);
Getting this error
[Tue Aug 18 14:41:57.614006 2015] [:error] [pid 21389] [client 67.90.138.68:5794] PHP Warning: file_get_contents(http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name=BR: Vigilante Crate): failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error\r\n
<?php
foreach($json2['rgDescriptions'] as $i){
$item = $i['market_name'];
$icon = $i['icon_url'];
$fetchdata = 'http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name=' . $item;
$grab = file_get_contents($fetchdata);
$id = json_decode($grab, true);
echo '<img src="'. $imgurlbase . $icon . '/64fx64f">' . '<a class="btn btn-primary btn-lg" href="#" role="button">' . $item . '</a>'. '<a class="btn btn-primary btn-lg" href="#" role="button">'. $id['lowest_price'].'</a>'.'<br>';
}
For some reason the & in the base url is getting passed as '& amp;' each time in the url and not as &
I am not the best with php, yet nothing I am searching for is coming up with why. Does it have to do with the json_decode? That is my only guess.
you need to encode the string:
$fetchdata = 'http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name=' . urlencode($item);
works for me:
php > $fetchdata ='http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name='.urlencode('BR: Vigilante Crate');
php > $grab = file_get_contents($fetchdata);
php > print_r(json_decode($grab));
stdClass Object
(
[success] => 1
[lowest_price] => $0.07
[volume] => 4,994
[median_price] => $0.07
)
I'm having trouble using the facebook api to post a photo to a page's wall. If I upload the file via php and use $_FILES[]["tmp_name"] as my $filelocation it works fine. However if I change $filelocation to a local filepath ( /tmp/1351750505-24d.jpg ) it doesn't work.
I've given my /tmp dir 777 and made sure my file is 777 as well to eliminate any permission issues. I've also used multiple files to make sure its not just an issue with one file.
The only other thought I have is that this could be a random setting in php.ini, but I didn't see anything glaring at me.
Error log:
[Thu Nov 01 06:52:13 2012] [error] [client 66.x.x.x] {"error":{"message":"(#1) An unknown error occurred","type":"OAuthException","code":1}}, referer: http://origin.example.com/adder/index.php
[Thu Nov 01 06:52:13 2012] [error] [client 66.x.x.x] $filelocation = /tmp/1351752730-24e.jpg, referer: http://origin.example.com/adder/index.php
[ec2-user#ip-10-x-x-x adder]$ ll /tmp/1351750505-24d.jpg
-rwxrwxrwx 1 apache apache 331 Nov 1 06:15 /tmp/1351750505-24d.jpg
$facebook->setFileUploadSupport(true);
$post_id = "";
try
{
$post_id = $facebook->api("/$page_id/photos", 'POST',
array(
'source' => '#' . $filelocation,
'message' => $name
));
error_log("\$filelocation = " . $filelocation);
} catch (FacebookApiException $e)
{
$result = $e->getResult();
error_log(json_encode($result));
$post_id["id"] = "FAIL!";
error_log("\$filelocation = " . $filelocation);
}
When I set $filelocation to /tmp/somefile.jpg it posts the local path/file fine. I notice one difference between your code and my code: I include the page access token in the POST call:
$local_path = '/tmp/water96x96.jpg';
$args = array(
'access_token' => $page_info['access_token'],
'message' => 'Testing photo upload via SDK!',
'source' => '#'.$local_path,
);
$post_id = $facebook->api('/'.$page_id.'/photos', 'post', $args);
To get the page access token, I do:
$page_info = $facebook->api('/'.$page_id.'?fields=access_token');
with a logged in user who is an admin of the page with manage_pages permission.
i was programming a mail templatingsystem. The user should be able to use markers in there, they will be replaced by the actual data. The problem ist, my function to replace the markers works just fine, but i need to do a recursiv call of that function, that will only run once, and this is what i came up with:
public function replace_placeholders($content, $recipient, $settings, $interface, $recommendation, $format, $recursion = false) {
$content = $this->replace_ph('briefanrede' , $recipient['id'] , $content);
$content = $this->replace_ph('anrede' , $recipient['title'] , $content);
$content = $this->replace_ph('email' , $recipient['email'] , $content);
$content = $this->replace_ph('kundennummer' , $recipient['kdnumber'] , $content);
$content = $this->replace_ph('briefanrede' , $recipient['briefanrede'] , $content);
if($recipient['title'] == $settings['anrede_w'] || $recipient['title'] == $settings['anrede_m']) {
$content = $this->replace_ph('vorname' , $recipient['forename'] , $content);
$content = $this->replace_ph('nachname' , $recipient['surename'] , $content);
} else {
$content = $this->replace_ph('vorname' , "" , $content, true);
$content = $this->replace_ph('nachname' , "" , $content, true);
}
$content = $this->replace_salutation($recipient, $settings, $content);
//Recommendation
if($this->need_replacement($content, 'weiterempfehlung') === false && $recursion === false) {
if($recommendation['own_page'] == 1) {
$baseurl = $recommendation['location'];
} else {
$baseurl = $recommendation['link'];
}
$pattern = ($format == "html") ? '%s' : '%s';
$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface, $recommendation, true);
$content = $this->replace_ph('weiterempfehlung' , (($format == "html") ? sprintf($pattern, $url, $settings['text_weiterempfehlung']): sprinf($pattern, $url)), $content);
}
return $content;
}
The recursiv call in this line
$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface, $recommendation, true);
is causing a 500 internal server error. I dont know why, because i think that i limited the recursion to run once. Can you help me out?
Sorry for my bad english i try hard to write clear sentences.
//EDIT:
Apache log:
[Wed May 30 15:31:56 2012] [warn] [client xx.xxx.xx.xxx] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Wed May 30 15:31:56 2012] [warn] [client xx.xxx.xx.xxx] (104)Connection reset by peer: mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
[Wed May 30 15:31:56 2012] [error] [client xx.xxx.xx.xxx] File does not exist: /var/www/web80/html/web80-newsletter/favicon.ico
[Wed May 30 15:31:58 2012] [error] mod_fcgid: process /var/www/php-fcgi/web80.php53/php-fcgi(21975) exit(communication error), get unexpected signal 11
the php errorlog is empty.
It would seem you miss one argument in your recursive call, making the $recursive = false continue being false all the time, which in turn makes your if statement
if($this->need_replacement($content, 'weiterempfehlung') === false && $recursion === false)
always return true.
Try adding one last variable to your recursive call instead and you should be able to properly execute your script, ie:
$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface,
$recommendation, true, true);
^ added one true
What i think you want to add instead of the first true is $format.
Signal 11 is SIGSEGV, i.e. the process crashed due to a bad memory access (such as dereferencing a NULL pointer or accessing memory it was not supposed to access).
This is nothing a PHP script should be causing, so you should first upgrade to the most recent stable PHP version and if it still happens reduce your script as much as possible (remove everything that can be removed while the crash still happens) and then report it as a PHP bug.