Well I am trying to post on facebook's wall but I get this error:
Fatal error: Call to undefined method stdClass::stream_publish()
The code I am trying is this
<?php
define('FB_APIKEY', '<Your Api Key>');
define('FB_SECRET', '<Secret>');
define('FB_SESSION', '<Session>');
require_once('facebook.php');
echo "post on wall";
echo "<br/>";
try {
$facebook = new Facebook(FB_APIKEY, FB_SECRET);
$facebook->api_client->session_key = FB_SESSION;
$facebook->api_client->expires = 0;
$message = '';
$attachment = array(
'name' => $_POST["name"],
'href' => $_POST["href"],
'description' => $_POST["description"],
'media' => array(array('type' => 'image',
'src' => $_POST["src"],
'href' => $_POST["href"])));
$action_links = array( array('text' => 'Visit Us', 'href' => '<link to some place here>'));
$attachment = json_encode($attachment);
$action_links = json_encode($action_links);
$target_id = "<Target Id>";
$session_key = FB_SESSION;
if( $facebook->api_client->stream_publish($message, $attachment, $action_links, null, $target_id)) {
echo "Added on FB Wall";
}
} catch(Exception $e) {
echo $e . "<br />";
}
?>
Well, as it is written in the error message there is no method "stream_publish" in $facebook->api_client.
Consult the manual of the library you are using to connect to the facebook.
If $facebook->api_client is not an object, then the line:
$facebook->api_client->session_key = FB_SESSION;
Will make php silently cast $facebook->api_client to an object of type stdClass. Which, later on down the code, will cause the Fatal error: Call to undefined method stdClass::stream_publish() that you are getting.
Try changing:
...
$facebook = new Facebook(FB_APIKEY, FB_SECRET);
$facebook->api_client->session_key = FB_SESSION;
$facebook->api_client->expires = 0;
...
to catch for when api_client is false (or, perhaps, not an object):
...
$facebook = new Facebook(FB_APIKEY, FB_SECRET);
if (!( $facebook->api_client )) {
//throw error
echo 'Need to sort this bit out';
exit;
}
$facebook->api_client->session_key = FB_SESSION;
$facebook->api_client->expires = 0;
...
And then, if that does throw an error, you'd need to investigate why $facebook->api_client is null.
Related
Im trying to get the text out xpath/html using php..but not successful any idea.
Example:
https://safeweb.norton.com/report/show?url=google.com
My xpath (This is correct i already double check)
//*[#id="bodyContent"]/div/div/div[3]/div[1]/div[1]/div[2]/div[1]/div/b
I want to get a result to appear here <div> result </div> using php
Below is my code:
<?php
public function getNortonSafe($domain)
{
try
{
$callback_url = "https://safeweb.norton.com/report/show?url=google.com"; //. $domain;
$curl_response = $this->curl->get($callback_url);
if ($curl_response->headers['Status-Code'] == "200") {
libxml_use_internal_errors(TRUE);
$this->dom_doc->loadHTML($curl_response);
libxml_use_internal_errors(FALSE);
$xpath = new DOMXPath($this->dom_doc);
$tmp = $xpath->query('//*[#id="bodyContent"]/div/div/div[3]/div[1]/div[1]/div[2]/div[1]/div/b')->item(0)->textContent);
$tmp = explode(' ', trim($tmp));
$norton_site_test = str_replace(",", "", $tmp[0]);
} else {
$norton_site_test = "0";
}
$response = array(
'status' => 'success',
'data' => array(
'norton_site_test' => filter_var($norton_site_test, FILTER_SANITIZE_STRING)
)
);
}
catch (Exception $e)
{
$response = array(
'status' => 'error',
'msg' => $e->getMessage()
);
}
return $response;
}
?>
HTML
<body>
<p id="norton_site_test"> result-text-here </p>
</body>
When executing the $xpath->query('some xpath here')->text(0) line an error occurs: Fatal error: Call to undefined method DOMNodeList::text(). Please check your PHP error reporting settings.
DOMXPath::query method returns DOMNodeList object that has only item method (see DOMNodeList).
You need to call:
$xpath->query('some xpath here')->item(0)->textContent
to get the text content of the first node from the received DOMNodeList object.
Just an Update regarding this code, and thank you to #camelsWrite - its working Now! with this clean code and tested:
public function getNortonSafe($domain)
{
try
{
$callback_url = "https://safeweb.norton.com/report/show?url= . $domain; //e.g $url: "https://safeweb.norton.com/report/show?url=google.com
$curl_response = $this->curl->get($callback_url);
if ($curl_response->headers['Status-Code'] == "200") {
libxml_use_internal_errors(TRUE);
$this->dom_doc->loadHTML($curl_response);
libxml_use_internal_errors(FALSE);
$xpath = new DOMXPath($this->dom_doc);
$tmp = $xpath->query('//*[#id="bodyContent"]/div/div/div[3]/div[1]/div[1]/div[2]/div[1]/div/b')->item(0)->textContent);
$tmp = explode(' ', trim($tmp));
$norton_site_test = str_replace(",", "", $tmp[0]);
} else {
$norton_site_test = "0";
}
$response = array(
'status' => 'success',
'data' => array(
'norton_site_test' => filter_var($norton_site_test)
)
);
}
catch (Exception $e)
{
$response = array(
'status' => 'error',
'msg' => $e->getMessage()
);
}
return $response;
} ?>
I am using php and mongodb. I want to use findandmodify. My field is { "_id" : ObjectId("58d37e612d4ffa498b99c2d4"), "userid" : "1234", "active_time" : "hai" }
I want to modify active_time. For example change the value "hai" to "1234"
I am using MongoDB\Driver\Manager.
try {
$mng = new MongoDB\Driver\Manager("mongodb://username:password#localhost:27017/db");
$userid = '1234';
$retval = $mng->findAndModify(
array("userid" => $userid), // searchQuery
array('$set' => array('active_time' => "kkk")) // UpdateQuery
);
$command = new MongoDB\Driver\Command($retval);
$cursor = $manager->executeCommand('db.online', $command);
} catch (MongoDB\Driver\Exception\Exception $e) {
$filename = basename(__FILE__);
echo "The $filename script has experienced an error.\n";
echo "It failed with the following exception:\n";
echo "Exception:", $e->getMessage(), "\n";
echo "In file:", $e->getFile(), "\n";
echo "On line:", $e->getLine(), "\n";
}
It shows the error is
Fatal error: Uncaught Error: Call to undefined method MongoDB\Driver\Manager::findAndModify()
in line
$retval = $mng->findAndModify(
array("userid" => $userid), // searchQuery
array('$set' => array('active_time' => "kkk")) // UpdateQuery
);
How it possible? please help me?
I got the answer. Change the findAndModify to update. The modified code is shown below.
$bulk->update(
array("userid" => '1234'), // searchQuery
array('$set' => array('active_time' => "kkk")) // UpdateQuery
);
$mng->executeBulkWrite("browser.online", $bulk);
if(!empty($mng)) {
echo "success";
} else {
echo "not";
}
Using the SoundCloud PHP wrapper, I can successfully update a song’s title, privacy, genre, tags. But I can't figure out what I'm doing wrong with regard to the streamable property. When I send a true value to track[streamable], it remains false.
Here’s what I’m working with:
<?php
require_once 'Soundcloud.php';
require './globaldatabase.php';
$access_token = $_POST['access_token'];
$trackid = $_POST['trackid'];
$title = $_POST['title'];
$genre = $_POST['genre'];
$tag_list = $_POST['tag_list'];
$privacy = $_POST['privacy'];
$release = $_POST['release'];
$streamable = true;
if($privacy=='disabled'){
$streamable = false;
$privacy = 'private';
}
$client = new Services_Soundcloud($sc_clientid, $sc_clientsecret);
$client->setAccessToken($access_token);
try {
$track = json_decode($client->get('tracks/'.$trackid));
$client->put('tracks/' . $track->id, array(
'track[title]' => $title,
'track[genre]' => $genre,
'track[tag_list]' => $tag_list,
'track[sharing]' => $privacy,
'track[release]' => $release,
'track[streamable]' => $streamable
));
$return = $client->get('tracks/' . $track->id);
$return_array[] = json_decode($return);
echo json_encode($return_array);
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}
?>
Try setting the track attribute api_streamable to true.
i'm trying to post photos on a fanpage and I get this error:
Fatal error: Uncaught OAuthException: (#120) Invalid album id thrown in /home/eyikmdnu/public_html/jack/facebook-sdk/base_facebook.php on line 1264
This is the code of the page (obv the token, the secret etc are not the "original"
require_once("../facebook-sdk/facebook.php");
define("APP_ID", "*****");
define("APP_SECRET", "********");
$fanpage_token = "*******";
$user_access_token = "********";
$config = array(
'appId' => APP_ID,
'secret' => APP_SECRET,
'fileUpload' => true // optional
);
$facebook = new Facebook($config);
//pagina = 358226040977616
//album id = 402459486554271
//$access_token = $_POST['access_token'];
//echo $access_token;
$facebook->setAccessToken($fanpage_token);
echo "Access Token Settato <br>\n";
$facebook->setFileUploadSupport(true);
echo "setFileUploadSupport(true) settato <br>\n";
$img_url = "images/jack.png";
//$img_url = $_POST['url'];
echo "$img_url = $img_url <br>\n";
$page_id = "358226040977616";
$album_id = "402459486554271";
echo "Page id: $page_id <br>\n";
echo "Album id: $album_id <br>\n";
$real_img_url = realpath($img_url);
echo "Real img url: $real_img_url <br>\n";
$args = array(
'message' => 'message to write in legend',
'image' => "#" . $img_url,
'aid' => $album_id,
'no_story' => 1,
'access_token' => $fanpage_token
);
echo "<br>\n";
print_r($args);
echo "<br>\n";
$photo = $facebook->api("/".$album_id."/photos", 'post', $args);
print_r($photo);
Need help! :O
I solved, the problem is that I should use the access_token of the page, that is not static, well I have to look in my /profile/accounts
$params = array('access_token' => $access_token);
$accounts = $facebook->api('/giacomo.torricelli/accounts', 'GET', $params);
foreach($accounts['data'] as $account) {
if( $account['id'] == $fanpage || $account['name'] == $fanpage ){
$fanpage_token = $account['access_token'];
}
}
Thanks
I'm having a heck of a time trying to get the status of a uploaded video to YouTube. I've followed the bellow URL to setup a CRON job that would send videos to YouTube, get a response; preferably with the YouTube ID so I can save this in a database. Down side is I can not get this to work.
http://framework.zend.com/manual/1.12/en/zend.gdata.youtube.html
My Code: (Which is basically copy and past from the above URL)
function upload($filename, $options = array()) {
$default = array_merge(
array(
'username' => 'USERNAME',
'password' => 'PASSWORD',
'service' => 'youtube',
'client' => null,
'source' => 'YouTube Component',
'loginToken' => null,
'loginCaptcha' => null,
'authenticationURL' => 'https://www.google.com/accounts/ClientLogin',
'applicationId' => 'YouTube Component',
'clientId' => 'YouTube Component',
'developerKey' => 'DEVELOPERS-KEY',
'content_type' => 'video/quicktime',
'title' => null,
'description' => null,
'category' => null,
'tags' => null,
),
(array)$options
);
extract($default);
$this->controller->Zend->loadClass('Zend_Gdata_YouTube');
$this->controller->Zend->loadClass('Zend_Gdata_ClientLogin');
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username,
$password,
$service,
$client,
$source,
$loginToken,
$loginCaptcha,
$authenticationURL
);
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$filesource = $yt->newMediaFileSource($filename);
$filesource->setContentType($content_type);
$filesource->setSlug($filename);
$myVideoEntry->setMediaSource($filesource);
$myVideoEntry->setVideoTitle($title);
$myVideoEntry->setVideoDescription($description);
$myVideoEntry->setVideoCategory($category);
$myVideoEntry->SetVideoTags($tags);
$myVideoEntry->setVideoPrivate();
$uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
try {
$newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
} catch (Zend_Gdata_App_HttpException $httpException) {
echo $httpException->getRawResponseBody();
} catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
try {
$control = $myVideoEntry->getControl();
} catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
if ($control instanceof Zend_Gdata_App_Extension_Control) {
if ($control->getDraft() != null && $control->getDraft()->getText() == 'yes') {
$state = $myVideoEntry->getVideoState();
if ($state instanceof Zend_Gdata_YouTube_Extension_State) {
print 'Upload status: ' . $state->getName() .' '. $state->getText();
} else {
print 'Not able to retrieve the video status information' .' yet. ' . "Please try again shortly.\n";
}
}
}
}
The above works in every way, minus the fact that I always get "Not able to retrieve the video status information...". What am I doing wrong? I've been staring at this for hours so I imagine its something simple that I've missed.
I wasn't to terribly far off with completing this. The answer was to replace all of the return code with (customized a bit because I need a return value as this is a CakePHP component.):
$state = $newEntry->getVideoState();
if ($state) {
$response['id'] = $newEntry->getVideoId();
} else {
$response['error'] = "Not able to retrieve the video status information yet. " .
"Please try again later.\n";
}
return $response;