I am using the following code post to my timeline. I am getting an error which is shown at the end of this post. Any ideas?
<?php
......
$request = 'https://graph.facebook.com/oauth/access_token';
$grant_type = 'client_credentials';
$client_id = '1504901xxxxxxxx'; //FaceBook Developer App_id LIVE
$client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; //Facebook Developer Api_secret LIVE
$postargs = 'grant_type=' . urlencode($grant_type) . '&client_id=' . $client_id . '&client_secret=' . $client_secret;
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
preg_match('/access_token=(.*)/', $response, $match);
curl_close($session);
$access_token = trim($match[1]);
$Application = 'WTSO';
$User = '1504901xxxxxxxx'; /*this is the user id*/
$target_id = '1647886xxxxxxxx';
$api_url = 'https://api.facebook.com/method/stream.publish?';
$server_loc = 'https://wtso.com';
$logo = new stdClass();
$attachment = new stdClass();
$logo->type = 'image';
$logo->src = 'http://admin.wtso.com' . '/images/' . (($new_products['image_name']) ? $new_products['image_name'] : 'xx1235.jpg');
$logo->href = $facebook_bitly;
$attachment->name = ' '; //'WTSO Product Notification';
$attachment->caption = (!empty($new_products['products_short_description'])) ? substr(strip_tags($new_products['products_short_description']), 0, 900) : $facebookText;
$attachment->description = ' ';
$attachment->href = $facebook_bitly;
$attachment->media = array($logo);
$message = (!empty($facebookText)) ? strip_tags($facebookText) : $new_products['products_name'];
$postargs2 = 'message=' . urlencode($message) . '&attachment=' . urlencode(json_encode($attachment)) . '&target_id=' . urlencode($target_id) . '&access_token=' . urlencode($access_token) . '&method=stream.publish';
$request2 = $api_url . $postargs2;
//Initiating a 2nd Curl instance
$session2 = curl_init($request2);
curl_setopt($session2, CURLOPT_HEADER, false);
curl_setopt($session2, CURLOPT_RETURNTRANSFER, true);
$response2 = curl_exec($session2);
curl_close($session2);
?>
I am getting this error from Facebook in $response2
<error_code>200</error_code>
<error_msg>Insufficient permission to post to target on behalf of the viewer</error_msg>
Related
I want to get the real-time LPR Result from a Hikvision LPR Camera. I have the link from Hikvision ISAPI Document: /ISAPI/Traffic/channels/1/vehicleDetect/plates
I get the following error:
<?xml version="1.0" encoding="UTF-8"?>
<ResponseStatus version="2.0" xmlns="http://www.std-cgi.com/ver20/XMLSchema">
<requestURL>/ISAPI/Traffic/channels/1/vehicleDetect/plates</requestURL>
<statusCode>6</statusCode>
<statusString>Invalid XML Content</statusString>
<subStatusCode>badXmlContent</subStatusCode>
</ResponseStatus>
This link does not work whereas the link /ISAPI/Traffic/channels/1/vehicleDetect/ works. Please help me to solve this problem.
Invalid XML Content
HTTP Content "0" < grab the last20 plates
HTTP Methods IS "POST" !!! not GET the documentation is wrong, A get never send any data to the serveur ;), this is why you get an invalid xml format at input
Works:
$username = 'xxxxx';
$password = 'yyyyy';
$url = "https://xxx.xxx.xxx.xxx/ISAPI/Traffic/channels/1/vehicleDetect/plates";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch,CURLOPT_TIMEOUT, 30);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "<AfterTime version=\"2.0\"><picTime>2020-06-20T00:00:00Z</picTime></AfterTime>");
$first_response = curl_exec($ch);
$info = curl_getinfo($ch);
preg_match('/WWW-Authenticate: Digest (.*)/', $first_response, $matches);
if(!empty($matches))
{
$auth_header = $matches[1];
$auth_header_array = explode(',', $auth_header);
$parsed = array();
foreach ($auth_header_array as $pair)
{
$vals = explode('=', $pair);
$parsed[trim($vals[0])] = trim($vals[1], '" ');
}
$response_realm = (isset($parsed['realm'])) ? $parsed['realm'] : "";
$response_nonce = (isset($parsed['nonce'])) ? $parsed['nonce'] : "";
$response_opaque = (isset($parsed['opaque'])) ? $parsed['opaque'] : "";
$authenticate1 = md5($username.":".$response_realm.":".$password);
$authenticate2 = md5("POST:".$url);
$authenticate_response = md5($authenticate1.":".$response_nonce.":".$authenticate2);
$request = sprintf('Authorization: Digest username="%s", realm="%s", nonce="%s", opaque="%s", uri="%s", response="%s"',
$username, $response_realm, $response_nonce, $response_opaque, $url, $authenticate_response);
$request_header = array($request);
$request_header[] = 'Content-Type:application/json';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch,CURLOPT_TIMEOUT, 30);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, "<AfterTime version=\"2.0\"><picTime>2020-06-20T00:00:00Z</picTime></AfterTime>");
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_header);
$result['response']= curl_exec($ch);
print_r($result['response']);
}
The same problem when I ommited to post the input parameter, this following CURL command returns badXmlContent:
curl --digest --user xxx:xxx
http://172.27.111.50/ISAPI/Traffic/channels/1/vehicleDetect/plates
But this one works ok:
curl --digest --user xxx:xxx
http://172.27.111.50/ISAPI/Traffic/channels/1/vehicleDetect/plates
-d "<AfterTime><picTime>2022-03-10T14:00:00Z</picTime></AfterTime>"
So the problem was omitting
-d "<AfterTime><picTime>2022-03-10T14:00:00Z</picTime></AfterTime>"
Hi here is my code please check it and let me know what im missing.
im using amazon orders API for this.
<?php
require_once('.config.inc.php');
//$serviceUrl = "https://mws.amazonservices.com/Orders/2013-09-01";
// Europe
$serviceUrl = "https://mws-eu.amazonservices.com/Orders/2013-09-01";
// Japan
//$serviceUrl = "https://mws.amazonservices.jp/Orders/2013-09-01";
// China
//$serviceUrl = "https://mws.amazonservices.com.cn/Orders/2013-09-01";
$config = array (
'ServiceURL' => $serviceUrl,
'ProxyHost' => null,
'ProxyPort' => -1,
'ProxyUsername' => null,
'ProxyPassword' => null,
'MaxErrorRetry' => 3,
);
$service = new MarketplaceWebServiceOrders_Client(
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
APPLICATION_NAME,
APPLICATION_VERSION,
$config);
$request = new MarketplaceWebServiceOrders_Model_ListOrdersRequest();
$request->setSellerId(MERCHANT_ID);
// object or array of parameters
echo"<pre>";
print_r($service);
invokeListOrders($service, $request);
function invokeListOrders(MarketplaceWebServiceOrders_Interface $service, $request)
{
try {
$response = $service->ListOrders($request);
echo ("Service Response\n");
echo ("=============================================================================\n");
$dom = new DOMDocument();
$dom->loadXML($response->toXML());
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
echo $dom->saveXML();
echo("ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
} catch (MarketplaceWebServiceOrders_Exception $ex) {
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
}
}
This is the XMl im using for getting the details i request somebody to reply me as soon as possible.
Just add these two lines after the
$request->setSellerId(MERCHANT_ID);
after this line add these two lines.
$request->setMarketplaceId(MARKETPLACE_ID);
$request->setCreatedAfter('2016-04-01');
Hope this helps..
My Select function of my QueryManager:
/**
* Führt eine SELECT - Query durch
*
* #param $select = array( array(column, [...]), table, shortcut )
* $orderby = array(column, sorting-type)
* $where = array( array( column, value, type[or, and] ), [...] )
* $innerjoin = array( table, shortcut, condition )
* $pagination = array( page, limit )
*
* #return array $data
*/
public function select($select,$orderby, $where, $innerjoin, $pagination)
{
$qb = $this->conn->createQueryBuilder()
->select($select[0])
->from($select[1], $select[2])
;
if ($orderby) {
$qb->orderBy($orderby);
}
if ($where) {
foreach($where as $cond) {
$x = 0;
if ( key($cond) == 0 ) {
$qb
->where($cond[0] . ' = ?')
->setParameter($x,$cond[1]);
}
elseif ( $cond[2] == 'and' ) {
$qb
->andWhere($cond[0] . ' = ?')
->setParameter($x,$cond[1]);
}
elseif ( $cond[2] == 'and' ) {
$qb
->orWhere($cond[0] . ' = :' . $x)
->setParameter($x,$cond[1]);
}
$x++;
}
}
if ($innerjoin) {
$qb->join($select[2],$innerjoin);
}
$this->sql = $qb->getSQL();
$this->totalRowCount = count( $qb->execute() ) ;
if ($pagination) {
$max = $pagination[0] * $pagination[1];
$first = $max - $limit;
$qb
->setFirstResult($first)
->setMaxResults($max)
;
}
$stmt = $qb->execute();
return $stmt->fetchAll();
}
I don't know why, but in action, this function produces a select query without inserted values for the parameters:
/**
* Lädt einen User nach dessen Username
*
* #param $username
* #return User $user | null
*/
public function getUser($username)
{
if($data = $this->select(array('*','users','u'), null, array( array('username',$username) ), null,null)) {
return $user = $this->hydrate($data);
}
return null;
}
I didn't get a result, and the query is not setup correctly:
array(0) { }
SELECT * FROM users u WHERE username = ?
In my opinion the Builder doesn't supstitute my parameters with the provided values ...
I got the latest version of Doctrine DBAL (2.4) and this version should support this features!
Thanks for Help and Suggestions :)
I also had this Problem. I have readed here doctrine 2 querybuilder with set parameters not working that:
You cant bind parameters to QueryBuilder, only to Query
But im creating SQL conditions as collected AND & OR experssions in deep nested objects, and the toppest object creates the query object. So i cant create the query object before, i always return expression objects.
So i solved the problem with direct including the variable into the prepared variable's position.
$qb->where($cond[0] . '=' . $cond[1]);
And because i expect strings there i added hard coded quotes. This is not the desired way, but at the moment i dont know how to solve that in an other way with binding parameters to the QueryBuilder object.
$expr = $d_qb->expr()->between($t_c, "'" . $date_from . "'", "'" . $date_from . "'");
Other suggestions?
Following codes results:
$expr = $d_qb->expr()->between($t_c, ':from', ':to');
$d_qb->setParameter('from', 1);
$d_qb->setParameter('to', 1);
or
$expr = $d_qb->expr()->between($t_c, ':from', ':to');
$d_qb->setParameter(':from', 1);
$d_qb->setParameter(':to', 1);
Results:
e0_.created BETWEEN ? AND ?
I'm new here and need help to fix my code.
I'm trying to make a code using DomXPath to grab title, url and description from bing search and then save it to my DB.
Here is the code :
<?php
$s="something-words";
$keywords = strstr($s, '-') ? str_replace('-', '+', $s) : $s;
$html5 = new DOMDocument();
#$html5->loadHtmlFile('http://www.bing.com/search?q='.$keywords.'&go=&qs=bs&filt=all');
$xpath5 = new DOMXPath($html5);
$nodes = $xpath5->query('//div[#class="sb_tlst"]/h3');
$nodes = $xpath5->query('//div[#class="sb_meta"]/cite');
$nodes = $xpath5->query('//div[#id="results"]/ul[#id="wg0"]/li/div/div/p');
$data = array();
$data2 = array();
$data3 = array();
$i = 0;
foreach ($nodes as $node) {
$data = $node->textContent;
$i++;
// insert table urlgrab
mysql_query( "INSERT INTO urlgrab(title) Values ('$data')");
$data2 = $node->textContent;
$i++;
// update table urlgrab
dbConnect();
mysql_query( "UPDATE urlgrab SET url='$data2' WHERE title='$data'" );
$data3 = $node->textContent;
$i++;
// update table urlgrab
dbConnect();
mysql_query( "UPDATE urlgrab SET description='$data3' WHERE title='$data'" );
}
?>
the problem is I get same results in database for title,url,description. How to fix this code to get all data title,url and description save to my DB?
As you have messed up you code so it's hard to identified. But by assumption I have generated below code which should work for you.
$titles = $xpath5->query('//div[#class="sb_tlst"]/h3');
$urls = $xpath5->query('//div[#class="sb_meta"]/cite');
$descriptions = $xpath5->query('//div[#id="results"]/ul[#id="wg0"]/li/div/div/p');
$arrTitle = array();
foreach($titles as $title){
$arrTitle[] = $title->textContent;
}
$arrUrl = array();
foreach($urls as $url){
$arrUrl[] = $url->textContent;
}
$arrDescription = array();
foreach($descriptions as $description){
$arrDescription[] = $description->textContent;
}
$i = 0;
dbConnect();
foreach ($i=0; $i < count($arrTitle); $i++) {
$title = $arrTitle[$i];
$url = $arrUrl[$i];
$description = $arrDescription[$i];
mysql_query( "INSERT INTO urlgrab(`title`, `url`, `description`) Values ('$title', '$url', '$description')");
}
*Remove $i++; in loop and then run. Actually we're doing $i++ in for loop * And that will solve your issue.
When I execute my code, the following exception was thrown (German):
Ausnahme beim Aufrufen von "GetListItems" mit 7 Argument(en):
"Exception of type
'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."
Is it possible to get more details about the Soap Server Exception?
My code:
$url = "http://mysharepoint.de/websites/test/"
$docBib = "TestDocLib"
$sitesWS = New-WebServiceProxy ($url + "_vti_bin/Lists.asmx") -UseDefaultCredential
$sitesWS.Proxy = New-Object System.Net.WebProxy("")
$xmlDoc = New-Object System.Xml.XmlDocument
$xmlDoc.LoadXml("<Document><Query /><ViewFields /><QueryOptions /></Document>")
$queryNode = $xmlDoc.SelectSingleNode("//Query")
$viewFieldsNode = $xmlDoc.SelectSingleNode("//ViewFields")
$queryOptionsNode = $xmlDoc.SelectSingleNode("//QueryOptions")
$queryNode.InnerXml = "<Where></Where>"
$sitesWS.GetList("test")
$result = $sitesWS.GetListItems($docBib, $null, $queryNode, $viewFieldsNode, $null, $queryOptionsNode, $null)
I've struggled with managing Sharepoint via web services as well. So I can tell how picky these can be with their arguments. This is how I set the GetListItems call up - and got it working:
$xmlDoc = new-object System.Xml.XmlDocument
$viewFields = $xmlDoc.CreateElement("ViewFields")
$queryOptions = $xmlDoc.CreateElement("QueryOptions")
$queryOptionsString = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><DateInUtc>TRUE</DateInUtc><ViewAttributes Scope='RecursiveAll' />"
$queryOptions.set_innerXML($queryOptionsString)
$query = $xmlDoc.CreateElement("Query")
$sitesWS = $service.GetListItems($docBib, "", $query, $viewFields, "", $queryOptions, "")
The trick, I think is that I create XML elements for each of $viewFields,$queryOptions and $query (but both viewFields and query can be empty except for their 'root' tags).