Create an Image Share on Linkedin API - php

I'm not able to Create an Image Share, can you put some example code please or check my code.
I've already tried "Create a Text Share", "Create an Article or URL Share" on this link : https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/share-on-linkedin (it work's)
I need to show if my code is good
I have create register_image() which work's well
Now I want to upload_image
public function upload_image($src_path, $image_request) {
if(!file_exists($src_path)) return -1;
$ch = curl_init();
if ($ch === false) {
throw new Exception('failed to initialize');
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $image_request['value']['uploadMechanism']['com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest']['uploadUrl'] . "&oauth2_access_token=" . $this->_access_token);
$postData = array(
'upload-file' => $src_path,
);
$str = http_build_query($postData);
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if ($response === false)
$response = curl_error($ch);
return $this->share_v3($image_request);
}
I get this error :
string(493) "HTTP/1.1 400 Bad Request Server: Play Set-Cookie: lang=v=2&lang=en-us; Path=/; Domain=api.linkedin.com Date: Fri, 10 May 2019 14:44:21 GMT Content-Length: 0 X-Li-Fabric: prod-lva1 Connection: keep-alive X-Li-Pop: prod-tln1 X-LI-Proto: http/1.1 X-LI-UUID: K6iDroJZnRXA+wxRVysAAA== Set-Cookie: lidc="b=VB41:g=2116:u=177:i=1557499460:t=1557553413:s=AQGsGR5wiWjwizsvGJEYdFeoQj-7IVF1" X-LI-Route-Key: "b=VB41:g=2116:u=177:i=1557499460:t=1557553413:s=AQGsGR5wiWjwizsvGJEYdFeoQj-7IVF1" "

Related

PHP Curl - eBay CSV FileExchange

I've tried to send a CSV File to eBay FileExchange Service.
I'm writing an application to update a lot of products on eBay at the same time.
When I upload the test.csv by using the eBay CSV-Manager the update will be success, but with the script nothing will happens after post the data.
I've treid the following steps:
Create a separate token for FileExchange.
https://signin.ebay.de/ws/eBayISAPI.dll?SignIn&runame=F-FILEEXL51P1EHH6L899Q9B969GE134DK-FileUpload
Then I use the following script:
$token = 'AgAAAA**AQAAAA**aAAAAA************';
$ebay_url = 'https://bulksell.ebay.com/ws/eBayISAPI.dll?FileExchangeUpload';
$sendheaders = array(
'User-Agent: My Client App v1.0'
);
$fields = array(
'token' => $token,
'file' => '#test.csv'
);
$ch = curl_init($ebay_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1); // set to 0 to eliminate header info from response
curl_setopt($ch, CURLOPT_NOBODY, 0); // set to 1 to eliminate body info from response
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // use HTTP/1.0 instead of 1.1
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response. ###
curl_setopt($ch, CURLOPT_HTTPHEADER, $sendheaders);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); // use HTTP POST to send form data
$resp = curl_exec($ch); //execute post and get results
if(!curl_exec($ch)) {
die('Error: ' . curl_error($ch) . ' - Code: ' . curl_errno($ch));
}
curl_close ($ch);
I've used this csv File-format (test.csv)
Action;ItemID;DispatchTimeMax
Revise;28*********916;30
The results after post:
print_r($resp);
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: dp1=bu1p/QEBfX0BAX19AQA**617d3da3^bl/DE617d3da3^; Domain=.ebay.com; Expires=Sat, 30-Oct-2021 12:42:11 GMT; Path=/
Set-Cookie: s=CgAD4ACBdvCgjMjFkNjZkMDcxNmUwYTBmMTc1MTA0ZmEwZmZmYjEyZWFY39RE; Domain=.ebay.com; Path=/
Set-Cookie: nonsession=CgADKACBhfT2jMjFkNjZkMDcxNmUwYTBmMTc1MTA0ZmEwZmZmYjEyZWIAywABXbrdqzHTwXKU; Domain=.ebay.com; Expires=Sat, 30-Oct-2021 12:42:11 GMT; Path=/
Cache-Control: private
Pragma: no-cache
Content-Type: text/html;charset=UTF-8
Content-Length: 731
Date: Thu, 31 Oct 2019 12:42:11 GMT
Connection: keep-alive
File upload successful. Your ref # is .
Close
Thanks for helping me.
I have found a solution:
Obviously at php 7.1 the # has no effect, and the file post ist empty to ebay.
I use the curl_file_create function and it's work.
if (!function_exists('curl_file_create'))
{
function curl_file_create($filename, $mimetype = '')
{
return "#$filename;filename="
. ($mimetype ? ";type=$mimetype" : '');
}
}
$fields = array(
"token" => $token,
"file" => curl_file_create ($_GET['filename'], 'text/csv')
);
Hope that help's anybody.

Subscribe using Superfeedr PubSubHubbub generating error hub.topic not found

I want to integrate Superfeedr API using PubSubHubbub in PHP. I am following this and my code is:
<?php
require_once('Superfeedr.class.php')
$superfeedr = new Superfeedr('http://push-pub.appspot.com/feed',
'http://mycallback.tld/push?feed=http%3A%2F%2Fpush-pub.appspot.com%2Ffeed',
'http://wallabee.superfeedr.com');
$superfeedr->verbose = true;
$superfeedr->subscribe();
?>
And my subscribe() function is
public function subscribe()
{
$this->request('subscribe');
}
private function request($mode)
{
$data = array();
$data['topic'] = $this->topic;
$data['callback'] = $this->callback;
$post_data = array (
"hub.mode" => 'subscribe',
"hub.verify" => "sync",
"hub.callback" => urlencode($this->callback),
"hub.topic" => urlencode($this->topic),
"hub.verify_token" => "26550615cbbed86df28847cec06d3769",
);
//echo "<pre>"; print_r($post_data); exit;
// url-ify the data for the POST
foreach ($post_data as $key=>$value) {
$post_data_string .= $key.'='. $value.'&';
}
rtrim($fields_string,'&');
// curl request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->hub);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_USERPWD, 'USERNAME:PASSWORD');
$output = curl_exec($ch);
if ($this->verbose) {
print('<pre>');
print_r($output);
print('</pre>');
}
}
But after execution I am getting this error
HTTP/1.1 422 Unprocessable Entity
X-Powered-By: The force, Luke
Vary: X-HTTP-Method-Override, Accept-Encoding
Content-Type: text/plain; charset=utf-8
X-Superfeedr-Host: supernoder16.superfeedr.com
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, PUT, DELETE
Access-Control-Allow-Headers: Authorization
Content-Length: 97
ETag: W/"61-db6269b5"
Date: Wed, 24 Aug 2016 14:01:47 GMT
Connection: close
Please provide a valid hub.topic (feed) URL that is accepted on this hub. The hub does not match.
Same data (topic and callback etc..) requesting from https://superfeedr.com/users/testdata/push_console
is working fine. But I don't know why I am getting this error on my local. If anyone has any experienced with same problom then please help me. Thanks.
You are using a strange hub URL. You should use HTTPS://push.superfeedr.com in the last param of your class constructor.

Can't connect to paypal adaptive API for paykey - getting 400 bad request error

I have been researching and trying for 2 days to make a test call with PayPal Adaptive API
I hand wrote a fairly simple test code using php cURL...
protected function makePayment($a=''){
if($a==''){return 'OOPs';}
$amount = "1.00";
$receiver = "RECEIVER TEST EMAIL";
$url = 'https://api-3t.sandbox.paypal.com/nvp/Pay';
$paypalHeaders = array(
'X-PAYPAL-SECURITY-USERID : XXXXXXXX',
'X-PAYPAL-SECURITY-PASSWORD : XXXXXXX',
'X-PAYPAL-SECURITY-SIGNATURE : XXXXXXX',
'X-PAYPAL-SECURITY-VERSION: 1.8.6',
'X-PAYPAL-DEVICE-IPADDRESS: <MY SITE IP>',
'X-PAYPAL-REQUEST-DATA-FORMAT : NV',
'X-PAYPAL-RESPONSE-DATA-FORMAT : NV',
'X-PAYPAL-APPLICATION-ID : APP-80W284485P519543T',
'X-PAYPAL-SANDBOX-EMAIL-ADDRESS: MY-SANDBOX-APP-OWNER#email.com'
);
// Format the call payload.
$payload = array(
"actionType"=>"PAY",
"currencyCode"=>"USD",
"receiverList"=>array(
"receiver"=>array(
array("amount"=>$amount,"email"=>$receiver)
)
),
"returnUrl"=>"https://biddingblock.com/api/payment.php",
"cancelUrl"=>"https://biddingblock.com/index.htm",
"requestEnvelope"=>array(
"errorLanguage"=>"en_US",
"detailLevel"=>"ReturnAll"
)
);
// Make the call
$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HEADER, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, $paypalHeaders);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $Request);
$Response = curl_exec($curl);
curl_close($curl);
return $Response;
* Every modification I have tried on this code still doesn't get past first base and I receive the following error back *
HTTP/1.1 400 Bad Request
Server: AkamaiGHost
Mime-Version: 1.0
Content-Type: text/html
Content-Length: 176
Expires: Mon, 31 Mar 2014 12:31:45 GMT
Date: Mon, 31 Mar 2014 12:31:45 GMT
Connection: close
An error occurred while processing your request.
Reference #166.d80300cc.1396269105.de2dda4
I am NOT using the Adaptive API PHP SDK and this is more or less the complete code minus the real keys and receiver email
What am I doing wrong?
Can someone please help?
PS: I have also tried this using DATA-FORMAT JSON and JSON encoding the payload array.
This is working for me:
$nvp = "&PAYMENTREQUEST_0_PAYMENTACTION=SALE";
$nvp.= "&PAYMENTREQUEST_0_AMT=19.95";
$nvp.= "&PAYMENTREQUEST_0_CURRENCYCODE=USD";
$nvp.= "&RETURNURL=http://www.dropial.com/success.html";
$nvp.= "&CANCELURL=http://www.dropial.com/cancel.html";
$response = wpp_hash('SetExpressCheckout', $nvp);
if ($response['ACK'] == 'Success') {
$this->Session->setFlash('Payment Successful');
} else {
$this->Session->setFlash('Payment Failed');
}
The function wpp_hash is defined as:
public function wpp_hash($method = null, $nvp = null) {
$curl_handler = curl_init();
curl_setopt($curl_handler, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp';
curl_setopt($curl_handler, CURLOPT_VERBOSE, 1);
curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handler, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handler, CURLOPT_POST, 1);
$required_nvp = 'METHOD='.$method;
$required_nvp .= '&VERSION='.urlencode(Configure::read('Paypal.version'));
$required_nvp .= '&USER='.urlencode(Configure::read('Paypal.username'));
$required_nvp .= '&PWD='.urlencode(Configure::read('Paypal.password'));
$required_nvp .= '&SIGNATURE='.urlencode(Configure::read('Paypal.signature'));
curl_setopt($curl_handler, CURLOPT_POSTFIELDS, $required_nvp.$nvp);
$http_responder = curl_exec($curl_handler);
curl_close($curl_handler);
pr($http_responder);
if (!$http_responder) {
throw new BadRequestException($method.'failed: '.curl_error($curl_handler).' ('.curl_errno($curl_handler).')');
}
$responder = explode('&', $http_responder);
$parsed_response = array();
foreach($responder as $response) {
$response_array = explode('=', $response);
if (count($response_array) >= 1){
$parsed_response[$response_array[0]] = urldecode($response_array[1]);
}
}
if ((count($parsed_response) < 1) || !array_key_exists('ACK', $parsed_response)){
throw new BadRequestException('Invalid HTTP Response for POST request ('.$required_nvp.$nvp.') to '.Configure::read('Paypal.endpoint'));
}
return $parsed_response;
}
You can change the method to use another PayPal transaction. In my case I'm using express checkout.
I have moved beyond this and used a work around by running this with the following method.
Thanks
Here is the solution I have adopted...
$payload = array(
"actionType"=>"PAY",
"currencyCode"=>"USD",
"receiverList"=>array(
"receiver"=>array(
array("amount"=>$amount,"email"=>$receiver)
)
),
"feesPayer"=>"PRIMARYRECEIVER",
"returnUrl"=>"MyRETURN_URL",
"cancelUrl"=>"MyCANCEL_URL",
"requestEnvelope"=>array(
"errorLanguage"=>"en_US",
"detailLevel"=>"ReturnAll"
)
);
$request = 'curl -s --insecure'.$TEST_url.' -d "'.addslashes(json_encode($payload)).'"';
$response = json_decode(exec($request));

How to perform a PUT operation using CURL in PHP?

I would like to perform a PUT operation on a webservice using CURL. Let's assume that:
webservice url: http://stageapi.myprepaid.co.za/api/ConsumerRegisterRequest/cac52674-1711-e311-b4a8-00155d4905d3
municipality= NMBM
sgc= 12345
I've written the code below, but it outputs this error message: "ExceptionMessage":"Object reference not set to an instance of an object.". Any help would be so much appreciated. Thanks!
<?php
function sendJSONRequest($url, $data)
{
$data_string = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json',
'X-MP-Version: 10072013')
);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
ob_start();
$result = curl_exec($ch);
$info = curl_getinfo($ch);
if ($result === false || $info['http_code'] == 400) {
return $result;
} else {
return $result;
}
ob_end_clean();
curl_close($ch);
}
$mun = $_GET['municipality'];
$sgc = $_GET['sgc'];
$req = $_GET['req']; //cac52674-1711-e311-b4a8-00155d4905d3
//myPrepaid PUT URL
echo $mpurl = "http://stageapi.myprepaid.co.za/api/ConsumerRegisterRequest/$req";
// Set Variables
$data = array("Municipality" => "$mun", "SGC" => "$sgc");
//Get Response
echo $response = sendJSONRequest($mpurl, $data);
?>
I copied your code, but changed it so it pointed at a very basic HTTP server on my localhost. Your code is working correctly, and making the following request:
PUT /api/ConsumerRegisterRequest/cac52674-1711-e311-b4a8-00155d4905d3 HTTP/1.1
Host: localhost:9420
Content-Type: application/json
Accept: application/json
X-MP-Version: 10072013
Content-Length: 37
{"Municipality":"NMBM","SGC":"12345"}
The error message you're receiving is coming from the stageapi.myprepaid.co.za server. This is the full response when I point it back to them:
HTTP/1.1 500 Internal Server Error
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 30 Aug 2013 04:30:41 GMT
Connection: close
Content-Length: 867
{"Message":"An error has occurred.","ExceptionMessage":"Object reference not set to an instance of an object.","ExceptionType":"System.NullReferenceException","StackTrace":" at MyPrepaidApi.Controllers.ConsumerRegisterRequestController.Put(CrmRegisterRequest value) in c:\\Workspace\\MyPrepaid\\Prepaid Vending System\\PrepaidCloud\\WebApi\\Controllers\\ConsumerRegisterRequestController.cs:line 190\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)"}
You may want to check out the API to make sure you're passing them the correct information. If you are, the problem could be on their end.
And while I realize this isn't part of your question and this is in development, please remember to sanitize any data from $_GET. :)
Try with:
curl_setopt($ch, CURLOPT_PUT, true);

How to paste data to pastebin using the api in php?

<?php
/* gets the data from a URL */
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$paste_data=""; if(isset($_POST["paste_code"])) { $paste_data = $_POST["paste_code"]; }
echo $paste_data;
$returned_content = get_data('http://pastebin.com/api_public.php/paste_code(paste_data)');
echo $returned_content;
?>
This is my php code . where $paste_data contains the data to be pasted in a new page . How do I paste it using the function paste_code(String) ?
The documentation says that you need to submit a POST request to
http://pastebin.com/api_public.php
and the only mandatory parameter is paste_code, of type string is the paste that you want to make.
On success a new pastebin URL will be returned.
Bare bone example:
$ch = curl_init("http://pastebin.com/api_public.php");
curl_setopt ($ch, CURLOPT_POST, true);
// A new paste with the string "hello there SO"
curl_setopt ($ch, CURLOPT_POSTFIELDS, "paste_code=hello there SO");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);
$response = curl_exec($ch);
echo $response;
and on running I get:
> POST http://pastebin.com/api_public.php HTTP/1.1
Host: pastebin.com
Accept: */*
Proxy-Connection: Keep-Alive
Content-Length: 25
Content-Type: application/x-www-form-urlencoded
< HTTP/1.1 200 OK
< Transfer-Encoding: chunked
< Date: Mon, 13 Dec 2010 07:51:12 GMT
< Content-Type: text/plain
< Server: nginx/0.8.52
< Vary: Accept-Encoding
< X-Powered-By: PHP/5.3.4-dev
< Via: 1.1 apac-nc06 (NetCache NetApp/6.0.6)
<
http://pastebin.com/Lc7kAw8Z* Closing connection #0
Clearly the response has the URL http://pastebin.com/Lc7kAw8Z
Visit it and you'll see a new paste containing hello there SO
FYI for others looking at this "post 2013", the api_public.php POST has been discontinued.
For those who stumple upon this thread via seach, here is a code that works in 2013:
<?php
$data = 'Hello World!';
$apiKey = 'xxxxxxx'; // get it from pastebin.com
$postData = array(
'api_dev_key' => $apiKey, // your dev key
'api_option' => 'paste', // action to perform
'api_paste_code' => utf8_decode($data), // the paste text
'api_paste_private' => '1', // 0=public 1=unlisted 2=private
'api_paste_expire_date' => '1D', // paste expires in 1 day
);
$ch = curl_init('http://pastebin.com/api/api_post.php');
curl_setopt_array($ch, array(
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => http_build_query($postData),
CURLOPT_RETURNTRANSFER => 1,
));
$re = curl_exec($ch);
curl_close($ch);
$pasteId = end(explode('/', $re));
echo "Created new paste.\r\n Link:\t{$re}\r\n Raw:\t" . sprintf('http://pastebin.com/raw.php?i=%s', $pasteId) . "\r\n";

Categories