Hello all happy holidays! :)
I'm trying to insert comments in my wordpress blog via the wp_insert_comment() function. It's for a plugin I'm trying to make.
I have this code in my header for testing. It works every time I refresh the page.
$agent = $_SERVER['HTTP_USER_AGENT'];
$data = array(
'comment_post_ID' => 256,
'comment_author' => 'Dave',
'comment_author_email' => 'dave#domain.com',
'comment_author_url' => 'http://www.someiste.com',
'comment_content' => 'Lorem ipsum dolor sit amet...',
'comment_author_IP' => '127.3.1.1',
'comment_agent' => $agent,
'comment_date' => date('Y-m-d H:i:s'),
'comment_date_gmt' => date('Y-m-d H:i:s'),
'comment_approved' => 1,
);
$comment_id = wp_insert_comment($data);
It successfully inserts comments into the database.
The problem: Comments don't show via the Disqus comment system. I compared table rows and I noticed that user_agent differs.
Normal comments use for example, Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv...
and Disqus comments use Disqus/1.1(2.61):119598902 numbers are different for each comment.
Does anyone know how to insert comments with wp_insert_comment() when Disqus is enabled?
You need to add this parameters:
'comment_type' => '',
Try to use this code:
$agent = $_SERVER['HTTP_USER_AGENT'];
$data = array(
'comment_post_ID' => 256,
'comment_author' => 'Dave',
'comment_author_email' => 'dave#domain.com',
'comment_author_url' => 'http://www.someiste.com',
'comment_content' => 'Lorem ipsum dolor sit amet...',
'comment_author_IP' => '127.3.1.1',
'comment_agent' => $agent,
'comment_type' => '',
'comment_date' => date('Y-m-d H:i:s'),
'comment_date_gmt' => date('Y-m-d H:i:s'),
'comment_approved' => 1,
);
$comment_id = wp_insert_comment($data);
I don't think Disqus imports comments from the WordPress database in real-time. If you wanted it to appear in Disqus' database immediately, you'd need to insert it via the Disqus API.
Related
I haveing trouble figuring out how to use Fedex's example file on tracking. I've got it communicateing with their test server, but I'm trying to get 'INCLUDE_DETAILED_SCANS' information from it. I can't figure out what syntax, of what to put to include it. I've found...
<xs:simpleType name="TrackRequestProcessingOptionType">
<xs:restriction base="xs:string">
<xs:enumeration value="INCLUDE_DETAILED_SCANS"/>
</xs:restriction>
</xs:simpleType>
So I've tried all sorts of variations of stuff like
$request['TrackRequestProcessingOptionType']=array('INCLUDE_DETAILED_SCANS' => true );
but I'm not getting anything extra. Has anybody used this... what am I missing? I'm just not understanding how it's using the TrackService_v8 file very well. I'm about to just change tactics and try writing it similar to an Ebay project I did which involved using curl and transmitting XML... although this might be slower...
Full code of request:
$request['WebAuthenticationDetail'] = array(
'UserCredential' =>array(
'Key' => 'asdfasdf',
'Password' => 'asdfasasdf'
)
);
$request['ClientDetail'] = array(
'AccountNumber' => 'asdfasdf',
'MeterNumber' => 'asdfas'
);
$request['TransactionDetail'] = array('CustomerTransactionId' => '*** Track Request v8 using PHP ***');
$request['Version'] = array(
'ServiceId' => 'trck',
'Major' => '8',
'Intermediate' => '0',
'Minor' => '0'
);
$request['TrackRequestProcessingOptionType']=array('INCLUDE_DETAILED_SCANS' => true );
$request['SelectionDetails'] = array(
'CarrierCode' => 'FDXE',
'PackageIdentifier' => array(
'Type' => 'TRACKING_NUMBER_OR_DOORTAG',
'Value' => 'asdfasdf' // Replace 'XXX' with a valid tracking identifier
)
);
Thank you in advance.
I have been trying to get a small PHP script to login in to a DOTNETNUKE application for a few days now with no avail. I have copied the headers and post variables EXACTLY as they are being sent using Tamper Data plugin for firefox.
Every time I send over the data I get the following error:
error=Your%20session%20has%20expired.%20%20Please%20try%20again
From what I can tell it's because the DOTNETNUKE Cookie is not being passed back and I am not sure why any help would be greatly appreciated. My GUZZLE code is below:
include_once(LIBRARY_PATH . '/guzzle.phar');
use Guzzle\Http\Client;
use Guzzle\Plugin\Cookie\CookiePlugin;
use Guzzle\Plugin\Cookie\CookieJar\ArrayCookieJar;
$cookiePlugin = new CookiePlugin(new ArrayCookieJar());
$client = new Client('ASPX URL CODE GOES HERE');
$client->addSubscriber($cookiePlugin);
$client->setUserAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0');
$response = $client->get('ASPX URL CODE GOES HERE')->send();
$request = $client->post('ASPX URL CODE GOES HERE', array(), array(
'__EVENTTARGET' => 'dnn$ctr383$LoginPage$SearchPage$dataPanel$ctl01$ctl13$LoginButton',
'__EVENTARGUMENT' => '',
'dnn$ReturnModuleFocus' => '',
'dnn$ModuleFocalPoint' => '',
'dnn$ModuleInvokedFromDataSearch' => '',
'dnn$ctr383$LoginPage$SearchPage$dataPanel$ctl01$ctl11$userName$mb_userName' => 'USERNAME HERE',
'dnn$ctr383$LoginPage$SearchPage$dataPanel$ctl01$ctl12$password$mb_password' => 'PASSWORD HERE',
'dnn$ctr383$LoginPage$SearchPage$dataPanel$ConfirmationSaveResponse' => '',
'dnn$ctr383$LoginPage$SearchPage$dataPanel$MinMax' => '',
'dnn$ctr383$LoginPage$SearchPage$dataPanel$dpPostBack' => '',
'ScrollTop' => '',
'__dnnVariable' => '',
'ScrollX' => '0',
'ScrollY' => '0',
'iCWindowID' => '2',
'iCRequestID' => '1',
'iCFieldsChanged' => '0',
'__VIEWSTATE' => ''
));
$response = $request->send();
echo $response;
Thanks ahead of time!
By looking at your code it seems like you are dealing with an asp site. I'm no good with ASP but i was scraping a lot of sites built with it and your problem is the __VIEWSTATE parameter.
ASP is using this random string for some sort of weird session handling. You can solve it easily by downloading the login form page and parsing out the __VIEWSTATE hidden input field's value
I'm having issues attempting to pull up tracking info using Fedex's Web Services. I am using a valid tracking number and I'm able to view the details on Fedex's site. However, I get an error 9040 "No information for the following shipments has been received by our system yet. Please try again or contact Customer Service at 1.800.Go.FedEx(R) 800.463.3339." Am I leaving something out?
My code:
<?php
$path_to_wsdl = "URL_TO_WSDL";
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1));
$request['WebAuthenticationDetail'] = array(
'UserCredential' =>array(
'Key' => 'MY_KEY',
'Password' => 'MY_PASSWORD'
)
);
$request['ClientDetail'] = array(
'AccountNumber' => 'MY_ACCT',
'MeterNumber' => 'MY_METER'
);
$request['TransactionDetail'] = array('CustomerTransactionId' => 'ActiveShipping');
$request['Version'] = array(
'ServiceId' => 'trck',
'Major' => '5',
'Intermediate' => '0',
'Minor' => '0'
);
$request['PackageIdentifier'] = array(
'Value' => 'TRACKING#',
'Type' => 'TRACKING_NUMBER_OR_DOORTAG');
$response = $client->track($request);
var_dump($response);
?>
Got it!
Call the web services departement and they told me to remove 'beta' from the wsdl file. This appears to be a different address than what I found in responses to this problem before. On line 1507 of the wsdl file, make the following change:
From:
<s1:address location="https://wsbeta.fedex.com:443/web-services/track"/>
To
<s1:address location="https://ws.fedex.com:443/web-services/track"/>
I changed the rest of my code slightly, but that shouldn't have made the difference. To be on the safe side, here it is:
<?php
$path_to_wsdl = "PATH_TO_WSDL_FILE";
$client = new SoapClient($path_to_wsdl, array('trace' => 1));
$trackRequest = array(
'WebAuthenticationDetail' => array(
'UserCredential' => array(
'Key' => 'MY_KEY',
'Password' => 'MY_PASSWORD'
)
),
'ClientDetail' => array(
'AccountNumber' => 'MY_ACCT_#',
'MeterNumber' => 'MY_METER_#'
),
'Version' => array(
'ServiceId' => 'trck',
'Major' => '5',
'Intermediate' => '0',
'Minor' => '0'
),
'PackageIdentifier' => array(
'Type' => 'TRACKING_NUMBER_OR_DOORTAG',
'Value' => 'THE_TRACKING_#',
),
'CustomerTrasactionId',
'IncludeDetailedScans' => 1
);
$response = $client->track($trackRequest);
var_dump($response);
?>
I'm also working on this same problem. I'm trying several things and you can see if anything works for you. Try including ShipDateRangeBegin and End elements, your test account/payer numbers or destination info. I've found here that switching to xml and ssl post requests supposedly solve the problem, but it's not an option for me. Maybe it will help you?
I have same problem when use xml-request. I solved the problem this way:
$endpointurl = "https://gatewaybeta.fedex.com:443/xml"; // remove word "beta"
$endpointurl = "https://gateway.fedex.com:443/xml";
...
$request = stream_context_create($form);
$browser = fopen($endpointurl , 'rb' , false , $request);
$response = stream_get_contents($browser);
...
I have a code like this.
<?php
include('IXR_Library.php');
$client = new IXR_Client('http://127.0.0.1/wordpress/xmlrpc.php');
$data = array(
'comment_post_ID' => 1,
'comment_author' => 'test_author',
'comment_author_email' => 'test#gmail.com',
'comment_author_url' => 'http://test.limewebs.com',
'comment_content' => 'Test Content',
'comment_type' => '',
'comment_parent' => 0,
'user_id' => 1,
'comment_author_IP' => '127.0.0.1',
'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
'comment_date' => $time,
'comment_approved' => 1,
);
if (!$client->query('wp.newComment','', 'username','password','12',$data)) {
die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());
}
$result = $client->wp_insert_comment($data);
print_r($result);
?>
In the above code, I get my comment posted to WordPress site, but the content(comment_content) is not getting posted.
Dude, remove all 'comment_' prefix to your array properties. Writing the WpAPI Class I dug deep in the heart of WP's XMLRPC. Parameters are always never in the order an normal person would put them. The names used are not consistent either. It's not a guessing game. Always look at the WP core code when not sure... [or use my Class ;)]
You're using invalid parameters on your request.
Wordpress XML-RPC_wp documentation lists the following parameters has valid for wp.newComment requests:
Parameters
int blog_id
string username
string password
int post_id
struct comment
int comment_parent
string content
string author
string author_url
string author_email
The following code should be enough to post a new comment on wordpress 3.3.5 (XML-RPC_wp api v3.1) via xmlrpc:
<?
include('IXR_Library.php.inc');
$client = new IXR_Client('http://myblog.com/xmlrpc.php');
$time = date("Ymd")."T".date("H:i:s")."Z";
$post_id = "630";
$data = array(
'author' => 'test_author',
'author_email' => 'test_comment#scroogle.org',
'author_url' => 'http://www.scroogle.org',
'content' => 'Comentario Teste scroogle.org',
'date' => $time,
'approved' => 1,
);
if (!$client->query('wp.newComment','', '','',$post_id, $data)) {
die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());
}
$result = $client->wp_insert_comment($data);
print_r($result);
?>
Note: In order to post anonymous comments via xmlrpc you'll need WordPress – Anonymous XMLRPC Comments Plugin
I'm having a recurring issue with PHP's inbuilt SOAP client where it returns the same error response regardless of the input paramaters.
Is there an advantage to using the SOAP library built into PHP or a disadvantage to directly querying via cURL through GET?
$client = new SoapClient("http://example.com/wdsl");
$params = array(
'Username' => 'username',
'Password' => 'pass',
'EventName' => 'Test Event',
'EventDate' => '2011-06-15T13:45:30',
'Destination' => '447987654321',
'Carrier' => '1',
'PhoneType' => '13',
'Originator' => 'ukflive',
'MessageText' => 'Test',
'LogoURL' => 'http://example.com/mail.gif',
'BookingReference' => '123456',
'Tickets' => '1',
'CollectionValidFrom' => '2011-06-15T13:45:30',
'CollectionValidTo' => '2011-06-15T18:45:30',
'TemplatePath' => '',
'PostBack' => 'http://example.com/'
);
$response = $client->__soapCall("SendManagedMobileTicket", $params);
print_r($response);
SoapClient is an integrated, actively maintained part of PHP5. cURL is the quick and dirty way to send HTTP data. The smart long term decision is to stick with SoapClient and its methods.
You may also want to look into the response headers, as shown in the notes section of the __soapCall() documentation page: http://www.php.net/manual/en/soapclient.soapcall.php#102387