Unknown authorization header error with Buzz API - Using Zend OAuth - php

Here's the response I keep getting when trying to create a new
activity:
{"error":{"errors":[{"message":"Unknown authorization
header","locationType":"header","location":"Authorization"}],"code":
401,"message":"Unknown authorization header"}}
Here's the request I sent (for debugging):
POST /buzz/v1/activities/#me/#self?alt=json HTTP/1.1
Host: www.googleapis.com
Connection: close
Accept-encoding: gzip, deflate
User-Agent: Zend_Http_Client
Content-Type: application/json
Authorization: OAuth
realm="",oauth_consumer_key="eawp.com",oauth_nonce="ce29b04ce6648fbb92efc8f08c1c0091",oauth_signature_method="HMAC-
SHA1",oauth_timestamp="1277934794",oauth_version="1.0",oauth_token="1%2FcBzo5ckGvCAm3wLWh1SDH3xQNoW--
yek1NVfUa1Qqns",oauth_signature="CUezSiMbvxyN1BTeb3uROlIx8gA%3D"
Content-Length: 86
{"data":{"object":{"type":"note","content":"Using OAuth with Twitter -
PHP Example"}}}
All the other requests to get the access_token worked just fine, but
now I'm not too sure why it's not working.
** Update
To assist with the debugging a bit more, here is the code in question:
$config = array(
//'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
//'version' => '1.0',
//'signatureMethod' => 'HMAC-SHA1',
'callbackUrl' => $callback,
'siteUrl' => $url,
'consumerKey' => $consumerKey,
'consumerSecret' => $consumerPass
);
$statusMessage = $title;
$token = unserialize($accessToken);
$client = $token->getHttpClient($config);
$client->setUri('https://www.googleapis.com/buzz/v1/activities/#me/
#self?alt=json');
$client->setMethod(Zend_Http_Client::POST);
$client->setEncType(Zend_Http_Client::ENC_FORMDATA);
$client->setHeaders('Content-Type: application/json');
$data = array(
'data' => array(
'object' => array(
'type' => 'note',
'content' => $statusMessage,
),
),
);
$dataXml = "<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:activity='http://activitystrea.ms/spec/1.0'>
<activity:object>
<activity:object-type>http://activitystrea.ms/schema/1.0/
note</activity:object-type>
<content type='html'>$statusMessage<content>
</activity:object>
</entry>";
//$client->setRawData($dataXml);
$client->setRawData(Zend_Json::encode($data));
//$client->setParameterPost("content", $statusMessage);
$response = $client->request();
** As you can see, I did a bit of testing with both the xml+atom and
json requests - not much luck with either.
Can you see anything clearly wrong there? And another reminder that I
am using Zend_Oauth.

I have some problem
Use option:
'requestScheme' => Zend_Oauth::REQUEST_SCHEME_QUERYSTRING
in your $config array
After this change my problem was solved
PS More code:
$OAuthConfiguration = array(
'version' => '1.0',
'requestScheme' => Zend_Oauth::REQUEST_SCHEME_QUERYSTRING,
'signatureMethod' => 'HMAC-SHA1',
'callbackUrl'=>'####',
'requestTokenUrl' => 'https://www.google.com/accounts/OAuthGetRequestToken',
'authorizeUrl' => 'https://www.google.com/buzz/api/auth/OAuthAuthorizeToken',
'accessTokenUrl' => 'https://www.google.com/accounts/OAuthGetAccessToken',
'consumerKey' => '####',
'consumerSecret' => '####',
);
$OAuthConsumer = new Zend_Oauth_Consumer($OAuthConfiguration);
//authorizeOAuth
$params = array(
'domain'=>'####',
'scope'=>'https://www.googleapis.com/auth/buzz'
);
$token = $OAuthConsumer->getRequestToken($params);
$_SESSION['token']['buzz'] = serialize($token);
$OAuthConsumer->redirect($params);
//callbackOAuth
if (!empty($_GET) && isset($_SESSION['token']['buzz'])) {
$token = $consumer->getAccessToken(
$_GET,
unserialize($_SESSION['token']['buzz'])
);
unset($_SESSION['token']);
return serialize($token);
} else {
return false;
}

Related

Passing body header with PHP

I'm trying make a Vimeo-API to upload subtitles/captions, following this guide: https://developer.vimeo.com/api/upload/texttracks#uploading-a-text-track-step-3
The guide gives 4 steps, I'm stalled in step 3.
Step 3:
To upload the text track, take the value of the link field from Step 2, and make a PUT request to this location: PUT https://api.vimeo.com{link}
Here is my code:
require 'Vimeo/autoload.php';
use Vimeo\Vimeo;
$client = new Vimeo("xxxxxxxxxxxxxxxxxxxxxx,xxxxxxxxxxxxxxxxxx,xxxxxxxxxxxxx");
include __DIR__ . '/Vimeo/autoload.php';
$clientId = "xxxxxxxxxxxxxxxxxxxxx";
$clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxx";
$scope = "public";
$userId = 9999999;
$lib = new \Vimeo\Vimeo($clientId, $clientSecret);
$token = $lib->clientCredentials($scope);
$lib->setToken('xxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$videos = $lib->request("/videos/99999999/texttracks", ["type"=>"captions", "language"=>"pt-BR", "name"=>"legenda"], "POST");
$link = $videos["body"]["link"];
$videos = $lib->request("/videos/99999999/texttracks/", ["link"=>$link, "body"=>"https://paste.ee/r/E3Q1K/0"], "PUT");
echo "<pre>".var_export($videos, true)."</pre>";
Output:
array (
'body' => NULL,
'status' => 405,
'headers' =>
array (
'Server' => 'nginx',
'Content-Type' => 'application/json',
'Allow' => 'GET,POST,OPTIONS',
'X-Vimeo-DC' => 'ge',
'Accept-Ranges' => 'bytes',
'Via' => '1.1 varnish',
'Content-Length' => '0',
'Date' => 'Wed, 22 May 2019 07:11:58 GMT',
'Connection' => 'keep-alive',
'X-Served-By' => 'cache-bwi5150-BWI, cache-lax8642-LAX',
'X-Cache' => 'MISS, MISS',
'X-Cache-Hits' => '0, 0',
'X-Timer' => 'S1558509118.323164,VS0,VE80',
'Vary' => 'Accept-Encoding',
),
)
So, the problem occur in this line:
$videos = $lib->request("/videos/99999999/texttracks/", ["link"=>$link, "body"=>"https://paste.ee/r/E3Q1K/0"], "PUT");
As you can see, the output body is NULL. How can I set up correctly body header? I'm trying make this API for three days, here is my last hope, I'll be very glad if you could help me.
Thank you

Facebook Ads SDK - Unsupported Post Request

I got some example scripts from Facebook App Management to use the Marketing API. When I run the script, I just get this error by curl:
'Unsupported post request. Object with ID \'105101623679981\' does not exist, cannot be loaded due to missing permissions, or does not support this operation.
I already tried to deactivate the Sandbox Mode and go public, tried many different scripts in different languages and also other keys.
Any Ideas?
This is the Script:
<?php
//Add all those Uses and the autoloader
$access_token = '<my_very_long_accessToken';
$ad_account_id = '<my_account_id>'; //<-- This is the Object in the Error Code
$app_secret = '<my_app_secret>';
$page_id = '<my_page_id>';
$app_id = '<my_app_is>';
$api = Api::init($app_id, $app_secret, $access_token);
$api->setLogger(new CurlLogger());
$fields = array(
);
$params = array(
'objective' => 'PAGE_LIKES',
'status' => 'PAUSED',
'buying_type' => 'AUCTION',
'name' => 'My Campaign',
);
$campaign = (new AdAccount($ad_account_id))->createCampaign(
$fields,
$params
);
$campaign_id = $campaign->id;
echo 'campaign_id: ' . $campaign_id . "\n\n";
$fields = array(
);
$params = array(
'status' => 'PAUSED',
'targeting' => array('geo_locations' => array('countries' => array('US'))),
'daily_budget' => '1000',
'billing_event' => 'IMPRESSIONS',
'bid_amount' => '20',
'campaign_id' => $campaign_id,
'optimization_goal' => 'PAGE_LIKES',
'promoted_object' => array('page_id' => $page_id),
'name' => 'My AdSet',
);
//...
Yeah. I got it. It has to be "act_"
So bad. The Script is really crappy. So many Errors. And it's created by facebook!

OpenSubtitles API 401 Unauthorized how to fix?

I'm trying to fetch subtitles from OpenSubtitles (http://trac.opensubtitles.org/projects/opensubtitles/wiki/XMLRPC) like this:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//Opensubtitles listing
function data($request){
$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml\r\nUser-Agent: PHPRPC/1.0\r\n",
'content' => $request
)));
$server = 'http://api.opensubtitles.org/xml-rpc'; // api url
$file = file_get_contents($server, false, $context);
$response = xmlrpc_decode($file);
return $response;
}
//Get token
$request = xmlrpc_encode_request("LogIn", array('', '', 'eng', 'TemporaryUserAgent'));
$token = data($request)['token'];
//Get listing
$request = xmlrpc_encode_request("SearchSubtitles", array(
'imdb' => '0462499',
'sublanguageid' => 'eng',
'season' => '',
'episode' => '',
'token' => $token
));
$response = data($request);
var_dump($response);
?>
However I keep getting 401 Unauthorized. Does anyone know how to fix this problem? I know it's not a problem with the API because I am able to retrieve the token just fine.
Try using your username/password instead empty string.
And change UserAgent in TemporaryUserAgent in Header as written in
http://trac.opensubtitles.org/projects/opensubtitles/wiki/DevReadFirst
The second request should be in the following format:-
$request = xmlrpc_encode_request("SearchSubtitles", array($token, array(array('sublanguageid' => 'eng', 'imdbid' => 'your_imdbid'))));
Hope this helps.

Fedex Web Services: ERROR 9040 - Can't pull up tracking

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);
...

Zend_Service_Twitter Oauth Incorrect Signature

I have sucessfully connected to twitter using Zend_Oauth_Consumer and got an access token, however when i try to use this access token i am getting an error.
This is the code:
$token = unserialize($twsession->access_token); # would be in DB
$twitter = new Zend_Service_Twitter(array(
'username' => $token->screen_name,
'accessToken' => $token
));
$response = $twitter->account->verifyCredentials();
This outputs:
Zend_Rest_Client_Result Object (
[_sxml:protected] => SimpleXMLElement Object
(
[request] => /1/account/verify_credentials.xml
[error] => Incorrect signature
)
[_errstr:protected] => )
I assume the code is actually correct, its hard to tell as the examples on the ZF site are incomplete.
FWIW i am using Zend Framework 1.10.8
some fields were missing:
$token = unserialize($twsession->access_token); # would be in DB
$twitter = new Zend_Service_Twitter(array(
'username' => $token->screen_name,
'accessToken' => $token
));
$response = $twitter->account->verifyCredentials();
should be:
$token = unserialize($twsession->access_token); # would be in DB
$twitter = new Zend_Service_Twitter(array(
'username' => $token->screen_name,
'accessToken' => $token,
'consumerKey' => YOUR_APP_CONSUMER_KEY,
'consumerSecret' => YOUR_APP_CONSUMER_SECRET,
'callbackUrl' => YOUR_CALLBACK_URL
));
$response = $twitter->account->verifyCredentials();
To confirm, for a valid signature you need all the same fields that you are using with Zend_Oauth_Consumer

Categories