I need to download (by php: curl, file_get_contents...) the post full picture to site folders.
I can get the post item data, even the full_picture url but when I want to download it by wget or curl the server responds with an 403.
If I try to download that url by browser, no problem, I can see it.
https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s720x720/12525704_987920591279679_1409522552_n.jpg?oh=33b2b223cc3e6c2ddd1a94f098c44457&oe=5748C6D2
But if I try from curl or wget I get a 401 response
wget https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s720x720/12525704_987920591279679_1409522552_n.jpg?oh=33b2b223cc3e6c2ddd1a94f098c44457&oe=5748C6D2
[1] 9988
[2] 9989
$ converted 'https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s720x720/12525704_987920591279679_1409522552_n.jpg?oh=33b2b223cc3e6c2ddd1a94f098c44457' (ANSI_X3.4-1968) -> 'https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s720x720/12525704_987920591279679_1409522552_n.jpg?oh=33b2b223cc3e6c2ddd1a94f098c44457' (UTF-8)
--2016-01-22 15:20:39-- https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s720x720/12525704_987920591279679_1409522552_n.jpg?oh=33b2b223cc3e6c2ddd1a94f098c44457
Resolving scontent.xx.fbcdn.net (scontent.xx.fbcdn.net)... 31.13.83.4, 31.13.83.4
Connecting to scontent.xx.fbcdn.net (scontent.xx.fbcdn.net)|31.13.83.4|:443... connected.
HTTP request sent, awaiting response... 403 Forbidden
2016-01-22 15:20:39 ERROR 403: Forbidden.
I've tried also appending the access token to the path:
...&access_token=XXXXXXXX
This is the json post item:
stdClass Object
(
[id] => 396231587217143_531401453700155
[created_time] => 2016-01-11T13:21:37+0000
...
[picture] => https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s130x130/12525704_987920591279679_1409522552_n.jpg?oh=34e4a1b419bb842c5f84441f9a781745&oe=574676AE
[full_picture] => https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s720x720/12525704_987920591279679_1409522552_n.jpg?oh=33b2b223cc3e6c2ddd1a94f098c44457&oe=5748C6D2
[attachments] => stdClass Object
(
[data] => Array
(
[0] => stdClass Object
(
[media] => stdClass Object
(
[image] => stdClass Object
(
[height] => 405
[src] => https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s720x720/12525704_987920591279679_1409522552_n.jpg?oh=33b2b223cc3e6c2ddd1a94f098c44457&oe=5748C6D2
[width] => 720
)
)
[target] => stdClass Object
(
[id] => 10153413586308403
[url] => https://www.facebook.com/WorldArchery/videos/10153413586308403/
)
[type] => video_inline
[url] => https://www.facebook.com/WorldArchery/videos/10153413586308403/
)
)
)
...
)
I'm getting post information from a facebook page this way.
Init the Facebook class:
$this->facebook = new Facebook([
'app_id' => $app_id,
'app_secret' => $app_secret,
'default_graph_version' => 'v2.5',
//'default_access_token' => '{access-token}', // optional
]);
Getting post data:
...
$fields = array(
'id',
'application',
'call_to_action',
'caption',
'created_time',
'description',
'from',
'icon',
'is_hidden',
'is_published',
'link',
'message',
'message_tags',
'name',
'object_id',
'picture',
'full_picture',
'place',
'privacy',
'properties',
'source',
'status_type',
'story',
'story_tags',
'targeting',
'to',
'type',
'updated_time',
'with_tags',
'actions',
// 'tags',
// 'object_attachment',
'feed_targeting',
'attachments',
);
$data = $this->facebook->get($id . '?fields=' . implode(',', $fields));
$item = json_decode($data->getBody());
$object (object) $item;
Ty to set the UA like #CBroe mentioned:
wget -U Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36 {your-url}
You may consider using cURL as an alternative:
Saving image from PHP URL
Related
I am using official Vimeo PHP client.
I can upload a video, and set privacy.embed to whitelist.
Then doc tells me:
To add a domain to the whitelist, send a PUT request to /videos/{video_id}/privacy/domains/{domain}.
I tried
$privacy_uri = $uri . "/privacy/domains/testdomain.tld";
$domain_add_response = $client->request($privacy_uri);
where
- $uri is the /vimeo/<video_id>
- $client is born from new Vimeo(CLIENT_ID, CLIENT_SECRET, VIMEO_TOKEN);
Problem
Printing the $domain_add_response I get a 405 error, probably because of Allow (see the following response dump)
Array
(
[body] =>
[status] => 405
[headers] => Array
(
[Server] => nginx
[Content-Type] => application/json
[Allow] => PUT,DELETE,OPTIONS
[X-Vimeo-DC] => ge
[Accept-Ranges] => bytes
[Via] => 1.1 varnish
[Content-Length] => 0
[Date] => Mon, 15 Apr 2019 08:30:47 GMT
[Connection] => keep-alive
[X-Served-By] => cache-bwi5125-BWI, cache-mxp19820-MXP
[X-Cache] => MISS, MISS
[X-Cache-Hits] => 0, 0
[X-Timer] => S1555317047.232635,VS0,VE148
[Vary] => Accept-Encoding
)
)
I imagine I must set the PUT method in my request, but ... how ?
Solution found looking at api source code: https://github.com/vimeo/vimeo.php/blob/master/src/Vimeo/Vimeo.php#L88
where the signature of request is
public function request($url, $params = array(), $method = 'GET', $json_body = true, array $headers = array()): array
I understand that I can fix the problem, simply passing an empty $params array and specifing PUT as request $method
I changed this line
$domain_add_response = $client->request($privacy_uri);
Into this form
$domain_add_response = $client->request($privacy_uri, [], 'PUT');
And it works as expected
I have a file I am using as a PHP to act as a config file to store info that might need to be changed frequently. I return the array as an object, like so:
return (object) array(
"host" => array(
"URL" => "https://thomas-smyth.co.uk"
),
"dbconfig" => array(
"DBHost" => "localhost",
"DBPort" => "3306",
"DBUser" => "thomassm_sqlogin",
"DBPassword" => "SQLLoginPassword1234",
"DBName" => "thomassm_CadetPortal"
),
"reCaptcha" => array(
"reCaptchaURL" => "https://www.google.com/recaptcha/api/siteverify",
"reCaptchaSecretKey" => "IWouldNotBeSecretIfIPostedItHere"
)
);
In my classes I have a constructor to call this:
private $config;
function __construct(){
$this->config = require('core.config.php');
}
And the use it like:
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('secret' => $this->config->reCaptcha->reCaptchaSecretKey, 'response' => $StrToken)));
However, I am given the error:
[18-Apr-2017 21:18:02 UTC] PHP Notice: Trying to get property of non-object in /home/thomassm/public_html/php/lib/CoreFunctions.php on line 21
I don't understand why this is happening considering the thing is returned as an object and it seemed to work for other people, as I got this idea from another question. Any suggestions?
In your example only $this->config is an object. The properties are arrays, so you would use:
$this->config->reCaptcha['reCaptchaSecretKey']
The object looks like this:
stdClass Object
(
[host] => Array
(
[URL] => https://thomas-smyth.co.uk
)
[dbconfig] => Array
(
[DBHost] => localhost
[DBPort] => 3306
[DBUser] => thomassm_sqlogin
[DBPassword] => SQLLoginPassword1234
[DBName] => thomassm_CadetPortal
)
[reCaptcha] => Array
(
[reCaptchaURL] => https://www.google.com/recaptcha/api/siteverify
[reCaptchaSecretKey] => IWouldNotBeSecretIfIPostedItHere
)
)
To have all objects you could JSON encode and then decode:
$this->config = json_decode(json_encode($this->config));
A SOAP request XML looks like the following:
<soapenv:Body>
<net:GetAvailability>
<net:request>
<inh:UserCredentials>
<inh:AgentID>**</inh:AgentID><inh:Password>**</inh:Password>
<inh:Username>**</inh:Username>
</inh:UserCredentials>
<net:AccessCircuit>
<arr:string>All</arr:string>
</net:AccessCircuit>
<net:RequestDetails xsi:type="net:TelephoneNumberAvailabilityRequest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<net:PerformMPFACCheck>No</net:PerformMPFACCheck>
<net:ProxyCLI>true</net:ProxyCLI>
<net:TelephoneNumber>0121****</net:TelephoneNumber>
</net:RequestDetails>
<net:UserConsent>Yes</net:UserConsent>
</net:request>
</net:GetAvailability>
</soapenv:Body>
What I need to do is send this XML request using PHP SOAP however im not able to get this working. My current code is as follows:
$APIParameters = array(
'request' => array(
'UserCredentials' => array(
'Username' => $this->apiUsername,
'Password' => $this->apiPassword,
'AgentID' => $this->apiResellerID,
),
'AccessCircuit' => array(
'string' => 'All'
),
'UserConsent' => 'Yes',
)
);
$APIParameters['request']['RequestDetails'] = new SoapParam( array('PerformMPFACCheck' => 'Yes', 'Postcode' => "****", 'ProxyCLI' => "true", 'TelephoneNumber' => '****'), "TelephoneNumberAvailabilityRequest");
print_r($APIParameters);
$apiResult = $SOAPClient->GetAvailability($APIParameters);
The print_r() returns the following:
Array
(
[request] => Array
(
[UserCredentials] => Array
(
[Username] => ****
[Password] => ****
[AgentID] => ****
)
[AccessCircuit] => Array
(
[string] => All
)
[UserConsent] => Yes
[RequestDetails] => SoapParam Object
(
[param_name] => TelephoneNumberAvailabilityRequest
[param_data] => Array
(
[PerformMPFACCheck] => Yes
[Postcode] => ****
[ProxyCLI] => true
[TelephoneNumber] => 0121****
)
)
)
)
Yet the SOAP request fails with a Fatal error: Uncaught SoapFault exception: [a:InternalServiceFault]. What am I doing wrong?! Appreciate any help!
first check that your wsld soap access granted using this code
<?php
// enter your url
$client = new SoapClient('enteryoururl');
var_dump($client->__getFunctions());
?>
then check which function have in this url if you have access and your function list show your function then try this
Fatal error: Uncaught SoapFault exception: [ns1:Client.AUTH_1] Authentication Failed
i am using codebird-php to post images on twitter, when i do that i get 200 ok http code but the image is not uploaded. Here is my code:
<?php
session_start();
require_once ('./src/codebird.php');
\Codebird\Codebird::setConsumerKey('74AFitlDilqB2HlFQ8Cjszz6I', 'tDlVndY7iJG8loFGG1sq3gJaj59CwNx6UV5o6wEtV0LJebNJ0y'); // static, see 'Using multiple Codebird instances'
$cb = \Codebird\Codebird::getInstance();
$access_token = $_SESSION['access_token'];
$cb->setToken($access_token['oauth_token'], $access_token['oauth_token_secret']);
//$reply = $cb->statuses_update('status=Whohoo, I just again tweeted!');
// send tweet with these medias
$reply = $cb->media_upload(array(
'media' => 'http://www.bing.com/az/hprichbg/rb/BilbaoGuggenheim_EN-US11232447099_1366x768.jpg'
));
print_r($reply);
?>
This is what i am getting on running it in my browser:
stdClass Object ( [media_id] => 540134777223790592 [media_id_string] => 540134777223790592 [size] => 179801 [image] => stdClass Object ( [w] => 1366 [h] => 768 [image_type] => image/jpeg ) [httpstatus] => 200 [rate] => )
PS: I am running it on localhost, tweeting text works but not image and i am using Abrahams oAuth for getting oAuth token.
i fixed it by changing
$reply = $cb->media_upload(array(
'media' => 'http://www.bing.com/az/hprichbg/rb/BilbaoGuggenheim_EN-US11232447099_1366x768.jpg'
));
to
$params = array(
'status' => 'Auto Post on Twitter with PHP http://goo.gl/OZHaQD #php #twitter',
'media[]' => 'http://www.bing.com/az/hprichbg/rb/BilbaoGuggenheim_EN-US11232447099_1366x768.jpg'
);
// send tweet with these medias
/*$reply = $cb->media_upload(array(
'media[]' => "#http://www.bing.com/az/hprichbg/rb/BilbaoGuggenheim_EN-US11232447099_1366x768.jpg"
));*/
$reply = $cb->statuses_updateWithMedia($params);
The specific 401 error message I get is:
"error":"invalid_client","error_description":"The client credentials are invalid"}"
This error isn't listed anywhere in the PayPal documentation. I am certain I am using the test credentials and using the correct sandbox endpoint. The error occurs when I attempt to get an access token.
This is the class where the access token is retrieved:
private function _generateAccessToken($config) {
$base64ClientID = base64_encode($this->clientId . ":" . $this->clientSecret);
$headers = array(
"User-Agent" => PPUserAgent::getValue(RestHandler::$sdkName, RestHandler::$sdkVersion),
"Authorization" => "Basic " . $base64ClientID,
"Accept" => "*/*"
);
$httpConfiguration = $this->getOAuthHttpConfiguration($config);
$httpConfiguration->setHeaders($headers);
$connection = PPConnectionManager::getInstance()->getConnection($httpConfiguration, $config);
//print_r($connection); die;
$res = $connection->execute("grant_type=client_credentials");
$jsonResponse = json_decode($res, true);
if($jsonResponse == NULL ||
!isset($jsonResponse["access_token"]) || !isset($jsonResponse["expires_in"]) ) {
$this->accessToken = NULL;
$this->tokenExpiresIn = NULL;
$this->logger->warning("Could not generate new Access token. Invalid response from server: " . $jsonResponse);
} else {
$this->accessToken = $jsonResponse["access_token"];
$this->tokenExpiresIn = $jsonResponse["expires_in"];
}
$this->tokenCreateTime = time();
return $this->accessToken;
}
This is the $connection variable I have when I print_r (I removed the authorization string):
PayPal\Core\PPHttpConnection Object( [httpConfig:PayPal\Core\PPHttpConnection:private] => PayPal\Core\PPHttpConfig Object ( [headers:PayPal\Core\PPHttpConfig:private] => Array ( [User- Agent] => PayPalSDK/rest-sdk-php 0.6.0 (lang=PHP;v=5.4.21;bit=64;os=Linux_2.6.18- 308.16.1.el5;machine=x86_64;openssl=0.9.8e-fips-rhel5;curl=7.24.0) [Authorization] => Basic REMOVED AUTHORIZATION STRING == [Accept] => */* ) [curlOptions:PayPal\Core\PPHttpConfig:private] => Array ( [32] => 3 [78] => 30 [19913] => 1 [13] => 60 [10018] => PayPal-PHP-SDK [10023] => Array ( ) [81] => 2 [64] => 1 ) [url:PayPal\Core\PPHttpConfig:private] => https://api.sandbox.paypal.com/v1/oauth2/token [method:PayPal\Core\PPHttpConfig:private] => POST [retryCount:PayPal\Core\PPHttpConfig:private] => 1 ) [logger:PayPal\Core\PPHttpConnection:private] => PayPal\Core\PPLoggingManager Object ( [loggerName:PayPal\Core\PPLoggingManager:private] => PayPal\Core\PPHttpConnection [isLoggingEnabled:PayPal\Core\PPLoggingManager:private] => 1 [loggingLevel:PayPal\Core\PPLoggingManager:private] => 3 [loggerFile:PayPal\Core\PPLoggingManager:private] => PayPal.log ))
As far I can tell, I have correct credentials, correct endpoint, not sure what else it could be?
A HTTP401 on /token is returned if the client_id/secret aren’t recognized (either the wrong credentials for the environment, or the credentials aren’t active).
Can you run a test via cURL to rule out any environment / code-specific issues?
curl -v -u "client_id:secret" "https://api.sandbox.paypal.com/v1/oauth2/token" -X POST -d "response_type=token&grant_type=client_credentials"
(Replace client_id and secret above with your own)
Make sure payment $config mode is Sandbox and clientId and clientSecret keys are Sandbox same time.