Twitter Video share using CodeBird API - api

I'm trying to share a video to Twitter Account but getting a response like below
stdClass Object ( [request] => /1.1/media/upload.json [error] => Segments do not add up to provided total file size. [httpstatus] => 400 [rate] => stdClass Object ( [limit] => 615 [remaining] => 613 [reset] => 1576651447 ) )
I don't know what to do to fix this issue. If anyone experienced this please let me know.
This is my code to share video to twitter.
\Codebird\Codebird::setConsumerKey(CONSUMER_KEY, CONSUMER_SECRET);
$cb = \Codebird\Codebird::getInstance();
$cb->setToken($access_token, $access_token_secret);
$file = $videopath;
$size_bytes = filesize($file);
$fp = fopen($file, 'r');
// INIT
$reply = $cb->media_upload([
'command' => 'INIT',
'media_type' => 'video/mp4',
'total_bytes' => $size_bytes
]);
$media_id = $reply->media_id_string;
// APPEND
$segment_id = 0;
while (! feof($fp)) {
$chunk = fread($fp, 1048576); // 1MB per chunk for this sample
$reply = $cb->media_upload([
'command' => 'APPEND',
'media_id' => $media_id,
'segment_index' => $segment_id,
'media' => $chunk
]);
$segment_id++;
}
fclose($fp);
// FINALIZE
$reply = $cb->media_upload([
'command' => 'FINALIZE',
'media_id' => $media_id
]);
if ($reply->httpstatus < 200 || $reply->httpstatus > 299) {
die();
}
// Now use the media_id in a Tweet
$reply = $cb->statuses_update([
'status' => $msg,
'media_ids' => $media_id
]);
I'm getting an error in the Finalize command result.
I tried to fix this but I can't because I don't know the exact reason for this issue and I didn't know how to handle and fix this. Can anyone help me to fix this? The above is the code I have used to share the post to the twitter account. And one thing is, the above code works fine when I tried to share the post immediately to twitter using this API but the issue is only when I tried to share the post by scheduling it with a specific time to share.
And when I trying to share a video below 1mb it gets shared. When I tried a video with 1mb or more than that I got the below error while sharing to account.
{"errors":[{"code":324,"message":"Invalid media id 1215261697298108416"}],"httpstatus":400,"rate":null}

Related

Access Custom S3 Metadata After Completing Multipart Upload

I'm wanting to access the custom metadata for an object uploaded via the S3 multipart upload after firing off the completeMultipartUpload method.
I initiate a multipart S3 upload with some added custom metadata like so:
$response = $this->client->createMultipartUpload([
'Bucket' => $this->bucket,
'Key' => $key,
'ContentType' => $type,
'Expires' => 60,
'Metadata' => [
'file-guid' => $fileGuid,
],
]);
When I complete the multipart upload, I'm wanting to access the file-guid metadata and pass it along in my response.
$result = $this->client->completeMultipartUpload([
'Bucket' => $this->bucket,
'Key' => $key,
'UploadId' => $uploadId,
'MultipartUpload' => [
'Parts' => $parts,
],
]);
$fileGuid = $result['?'] // Couldn't find the metadata in the result.
return response()->json(['file-guid' => $fileGuid]);
I've checked the S3 object after it's been uploaded and it shows the custom metadata, but I don't see how to access it. I assumed it would be part of the completeMultipartUpload response, but I'm not seeing it.
Any help would be appreciated. Thanks!
I found a solution, but it involves an additional request. If anyone knows of a way to access the metadata without making another request, that would be better.
$headObject = $this->client->headObject([
'Bucket' => $this->bucket,
'Key' => $key,
]);

eBay API in Perl - can't use SetShipmentTrackingInfoRequest to update tracking information

I'm trying to figure out why I can't seem to update a tracking number using the eBay API. Here is the page I'm referencing:
http://developer.ebay.com/DevZone/merchant-data/CallRef/SetShipmentTrackingInfo.html
Based on that, I've got the following code in Perl:
use Net::eBay;
my $ebay = new Net::eBay( {
SiteLevel => 'prod',
DeveloperKey => 'x',
ApplicationKey => 'xxxx',
CertificateKey => 'xxx',
Token => 'xxxx',
} );
$ebay->setDefaults( { API => 2, compatibility => 900 } );
my $result = $ebay->submitRequest( "SetShipmentTrackingInfoRequest",
{
DetailLevel => "ReturnAll",
ErrorLevel => "1",
SiteId => "1",
OrderID => 1234546, # not the real order ID I'm using :)
ShipmentTrackingDetails => {
ShipmentTrackingNumber => "12345",
ShippingCarrierUsed => "Hermes"
}
});
print $IN->header;
use Data::Dumper;
print Dumper($result);
When running it, I get an error in $result:
$VAR1 = {
'Errors' => {
'ErrorClassification' => 'RequestError',
'SeverityCode' => 'Error',
'ShortMessage' => 'Unsupported API call.',
'ErrorCode' => '2',
'LongMessage' => 'The API call "SetShipmentTrackingInfoRequest" is invalid or not supported in this release.'
},
'xmlns' => 'urn:ebay:apis:eBLBaseComponents',
'Timestamp' => '2016-10-21 07:03:04',
'Build' => '18007281',
'Version' => '900',
'Ack' => 'Failure'
};
I'm a bit confused, as it looks like SetShipmentTrackingInfoRequest is the API call I need to be making? I've not really done much with the eBay API, so it's possible I'm missing something stupid.
UPDATE: As per feedback below, I'm now using the CompleteSale API call:
http://developer.ebay.com/Devzone/XML/docs/Reference/eBay/CompleteSale.html
my $result = $ebay->submitRequest( "CompleteSale ",
{
DetailLevel => "ReturnAll",
ErrorLevel => "1",
SiteId => "1",
OrderID => 1933420817015,
Shipment => {
ShipmentTrackingDetails => {
ShipmentTrackingNumber => "77293124902615",
ShippingCarrierUsed => "Hermes"
}
}
});
When I run it, I now get the error:
'LongMessage' => 'XML Error Text: "; nested exception is:
org.xml.sax.SAXParseException: Attribute name "Request" associated with an element type "CompleteSale" must be followed by the
\' = \' character.".',
Enabling debugging, the XML being sent is:
<?xml version='1.0' encoding='utf-8'?>
<CompleteSale Request xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>xxxx</eBayAuthToken>
</RequesterCredentials>
<DetailLevel>ReturnAll</DetailLevel>
<ErrorLevel>1</ErrorLevel>
<OrderID>xxxxx</OrderID>
<Shipment>
<ShipmentTrackingDetails>
<ShipmentTrackingNumber>xxxx</ShipmentTrackingNumber>
<ShippingCarrierUsed>Hermes</ShippingCarrierUsed>
</ShipmentTrackingDetails>
</Shipment>
<SiteId>1</SiteId>
</CompleteSale Request>
From looking at the eBay API doc link you posted doesn't the second 'Note' entirely explain why it doesn't work as a single API call?
Note: SetShipmentTrackingInfo cannot be issued on its own like an ordinary API call, using an endpoint
It then goes on to say:
In the Trading API, the CompleteSale call provides similar functionality that you can invoke directly
So perhaps looking there should be the next step

Twitter API Media Upload not working

I am working on Twitter API to create a functionality for the users to tweet directly from the software:
Here is my code:
$connection = new TwitterOAuth($this->getTwitterbpTable()->getConsumerKey(), $this->getTwitterbpTable()->getConsumerSecret(), $account->oauth_token , $account->oauth_secret);
$connection->setTimeouts(10, 150);
$media1 = $connection->upload('media/upload', ['media' => 'https://bleupagereview.files.wordpress.com/2014/02/bleupage.png']);
$parameters = [
'status' => 'My Media tweet here',
'media_ids' => implode(',', [$media1->media_id_string])
];
$connection->post('statuses/update', array('status' => $parameters));
The scripts works fine (does not throw any error/exception), but instead of uploading the file, it simply tweets the media id.
How should I change it so that it uploads the media file with status message.
Post function should be like this:
$connection->post('statuses/update', $parameters);

$facebook->getUser() always return 0

I tried to build facebook game but I stuck in saving score.
I have tried exactly as written in http://developers.facebook.com/docs/guides/games/getting-started/#step4 but It just simply wouldn't save the score.
I thought the problem is in this listing :
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));
$user = $facebook->getUser();
print('user : '.$user.' ');
there is always 0 although my fb account had logged in. With this problem I couldn't save nor update the high score. I need help to find the way to retrieve the $user.
I really appreciate every favor to me. Thank you...
Do you have this part?
// If the user has not installed the app, redirect them to the Auth Dialog
if (!$user) {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => $scope,
'redirect_uri' => $app_url,
));
print('<script> top.location.href=\'' . $loginUrl . '\'</script>');
}
Its required to log user and get his data.
Here is good explanation http://developers.facebook.com/docs/authentication/server-side/

$facebook->getSignedRequest(); return the correct value in iframe while return null on my server side

i am building a fan gate for my site to give out some coupon.
here is my code:
<?php
require_once 'facebook.php';
$app_id = "xxxxxxxxxxxxxxx";
$app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
print_r($_REQUEST);
$signed_request = $facebook->getSignedRequest();
echo "<pre>";
print_r($facebook->getSignedRequest());
echo "</pre>";
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
$like_status = $signed_request["page"]["liked"];
print_r($facebook);
?>
I find that the return value of $facebook->getSignedRequest(); is different when i am visiting my apps via apps.facebook.com/xxxxxxxxxxxxxxxxxxxxxx/ and when i am visiting www.coupon.mysite.com/facebook/index.php
via apps.facebook.com/xxxxxxxxxxxxxxxxxxxxxx/:
Facebook Object ( [appId:protected] => 15255288xxxxxxxx [appSecret:protected] => XXXXXXXXXXXXXXXXXXXX[user:protected] => [signedRequest:protected] => Array ( [algorithm] => HMAC-SHA256 [issued_at] => xxxxxxxxxxxxx[user] => Array ( [country] => hk [locale] => en_US [age] => Array ( [min] => 21 ) ) ) [state:protected] => [accessToken:protected] => [fileUploadSupport:protected] => )
via www.coupon.mysite.com/facebook/index.php:
Facebook Object ( [appId:protected] => xxxxxxxxxxxxxxxxxxx[appSecret:protected] => xxxxxxxxxxxxxxxxxx[user:protected] => [signedRequest:protected] => [state:protected] => [accessToken:protected] => [fileUploadSupport:protected] => )
so the fan gate wont work because $facebook->getSignedRequest(); always return null in my server side. I have do the searching for this problem for some days already and still dont understand what is the problem.
Any help is very much appreciated.
^ ... continue from the comments:
First of all, if you do this, your users will hate you; secondly, that plugin is bit of a scam - all it does is uses cookies to store if user has liked a page - but if you delete your cookies, you will be locked out of the content because you won't be able to like the page again. Furthermore, it won't work without Javascript.
All the plugin does is it hooks into the "like" action when user clicks on the like button via
FB.Event.subscribe('edge.create', function(href, response){});
facebook graph api determine if user likes url