I am not a hardcore coder but i have small knowledge i have attempted to fix this error we are getting regarding the Twitter api
there is a line of code that checks that a twitter name is currect which is sent via a form
$url = get_data("http://api.twitter.com/1/users/lookup.json?screen_name=".$name);
$xml = json_decode($url, true);
$id = $xml[0]['id'];
$av = $xml[0]['profile_image_url'];
if ($id != "")
What i understand
I understand that this version of twitter is no longer available and i need to update it to 1.1
What searching and research i have done
I have Searched the net for a quick answer for this but was not able to find any....
I have found this code https://github.com/abraham/twitteroauth/tree/master/twitteroauth
My question
How do i adapt the files to work within this file? i didnt post the whole code within the page as im not sure all of it is relevant.
Just use the 1.1 in the URL. That will do
http://api.twitter.com/1.1/users/lookup.json
-------^
Do like this...
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN,OAUTH_SECRET);
$account = $connection->get('account/verify_credentials');
$status = $connection->post('statuses/update', array('status' => 'Text of status here', 'in_reply_to_status_id' => 123456));
$status = $connection->delete('statuses/destroy/12345');
Documentation
Related
I've been trying to post an image with a simple message onto twitter using PHP and twitteroauth.php.
However, every time I run my code, I only get the $tweetMessage published on the twitter feed without any image.
I searched and searched and read their own documentation but don't even get me started on their own documentation! its like someone who's had a sleepwalk was writing their documentation. Just a bunch of jargon..
And most of the information on STO is either outdated or pointing to a library!
I do not want to use any library as I will have to try to learn someone else's code as well and Surely twitter would allow publishing photo's using their own API without the use of any third party Library?!
Any way, This is my full code:
// Include twitteroauth
require_once('inc/twitteroauth.php');
// Set keys
$consumerKey = 'xxxxxxxxxxxxxxxxxxx';
$consumerSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$accessToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$accessTokenSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
// Create object
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
// Set status message
$tweetMessage = 'This is a tweet to my Twitter account via PHP.';
$image_path="https://www.google.co.uk/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png";
$handle = fopen($image_path,'rb');
$image = fread($handle,filesize($image_path));
fclose($handle);
// Check for 140 characters
if(strlen($tweetMessage) <= 140)
{
// Post the status message
$tweet->post('statuses/update', array('media[]' => "{$image};type=image/jpeg;filename={$image_path}", 'status' => $tweetMessage));
}
Could someone please advise on this issue?
Thanks in advance.
EDIT:
I've changed my code to the following and I get this error:
{"errors":[{"code":195,"message":"Missing or invalid url parameter."}]}
But I'm sure the image is on the specified URL/directory!
This is the code:
require_once 'inc/twitteroauth.php';
define("CONSUMER_KEY", "xxxxxxxxxxxxxxxxx");
define("CONSUMER_SECRET", "xxxxxxxxxxxxxxxxxxxxxxxxxx");
define("OAUTH_TOKEN", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("OAUTH_SECRET", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
$content = $connection->get('images/sign-in-with-twitter-l.png');
$image = 'images/sign-in-with-twitter-l.png';
$status_message = 'Attaching an image to a tweet';
$status = $connection->post('statuses/update_with_media', array('status' => $status_message, 'media[]' => file_get_contents($image)));
echo json_encode($status);
Any idea why this error is being shown?
Uploading media to Twitter is slightly complicated. Essentially, it's a three stage process.
Upload the photo to Twitter.
Receive a media_id back from Twitter.
Post your status and media_id to Twitter.
This is described in great detail at https://dev.twitter.com/rest/reference/post/media/upload
Generally speaking, it is easier for use to use a library like CodeBird as they've already done the hard work of finding all the edge cases.
But, assuming you don't want to do that...
POST the image to /1.1/media/upload.json
Receive back some JSON like
{
"media_id": 553656900508606464,
"media_id_string": "553656900508606464",
"size": 998865,
"image": {
"w": 2234,
"h": 1873,
"image_type": "image/jpeg"
}
}
* Use that media_id_string when you post the status. e.g.
tweet->post('statuses/update', array('media_ids' => $media_id_string, 'status' => $tweetMessage));
Hopefully that gives you enough to understand what's going on.
I solved it like this:
$tweet_img = 'Path/to/image';
$handle = fopen($tweet_img,'rb');
$image = fread($handle,filesize($tweet_img));
fclose($handle);
$parameters = array('media[]' => "{$image};type=image/jpeg;filename={$tweet_img}",'status' => 'Picture time');
$returnT = $connection->post('statuses/update_with_media', $parameters, true);
Horrible twitter API documentation needs improving!! it needs to be written by humans as opposed to a bunch of sleepwalking zombies!!!
This is a very frustrating situation that they put us in when we try to use their API...
They either need stop their API support and remove it all from the public or simply improve their documentation and write it for the public and not just for their own use using jargon words.
Any way, the above code works just fine using the latest twitteroauth
I hope this helps others in my situation.
I feel like i wasted 5 hours for something that should be clear and mentioned in plain English on their site!!!
Rant and Answer over & good luck.. :)
I'm trying to use Codebird to show my latest tweet on a simple website. Unfortunately, I can't manage to make it work.
Here's what I did for now.
I created my App on Twitter Developer page. I obtained my Key/Secret and then my Token/Secret. Then I wrote my small PHP script and tried to show the timeline just to see if everything works. Here I encountered the problems. The code goes like this:
<?php
require_once ('codebird.php');
\Codebird\Codebird::setConsumerKey(MY_KEY, MY_SECRET);
$cb = \Codebird\Codebird::getInstance();
$cb->setToken(MY_TOKEN, MY_TOKEN_SECRET);
$reply = (array) $cb->statuses_homeTimeline();
print_r($reply);
?>
(and obviously I put the various key strings in the correct arguments).
This code gives my an Array ( [httpstatus] => 0 ). So I tried
print_r($reply[0]);
But then nothing is printed out in the page.
Where am I wrong? How should I modify this code to get my last tweet? I'm a bit new with the new Twitter API, and a lot of stuff confuses me.
Thank you for your help!
I copied and pasted your code and it's not working.
I get error regarding the CodeBird class
Try:
require_once ('codebird.php');
Codebird::setConsumerKey('key', 'secret key');
$cb = Codebird::getInstance();
$cb->setToken('token', 'secret token');
$reply = (array) $cb->statuses_homeTimeline();
this should work just fine.
<?php
use Codebird\Codebird;
require 'vendor/autoload.php';
$cb = new Codebird;
$cb->setConsumerKey(
'Consumer_Key',
'Consumer_Secret'
);
$cb->setToken(
'Access_Token',
'Access_Token_Secret'
);
$reply = (array)$cb->statuses_homeTimeline();
echo '<pre>';
print_r($reply);
I'm trying to create a script to add items to my test ebay account. But I've hit a problem I'm not sure if I have the wrong file set? but it doesn't seem to match up to the documentation (or I'm reading it wrong).
The file set I have is PHP Toolkit with 527 Support. There is also PHP Toolkit with 515 Support. Both from https://www.x.com/developers/ebay/php-accelerator-toolkit-ebay-trading-api-edition
I've found this great script through another question on stack overflow
https://github.com/iloveitaly/ebay-php/blob/master/eBayCommon.php
And I've been looking at the online help files here: http://developer.ebay.com/devzone/xml/docs/WebHelp/wwhelp/wwhimpl/js/html/wwhelp.htm
Here is the error I'm getting: PHP Fatal error: Class 'ReturnPolicyType' not found
The way I understand it is that there should be a file for each "Type" there is one for CategoryType and AmountType but no file for ReturnPolicyType. And no reference to it any any of the files I have.. am I looking at this totally wrongly?
require_once '../EbatNs/EbatNs_ServiceProxy.php';
require_once '../EbatNs/EbatNs_Logger.php';
require_once '../EbatNs/VerifyAddItemRequestType.php';
require_once '../EbatNs/AddItemRequestType.php';
require_once '../EbatNs/ItemType.php';
require_once '../EbatNs/ItemConditionCodeType.php';
require_once '../EbatNs/GetMyeBaySellingRequestType.php';
require_once '../EbatNs/GetMyeBaySellingResponseType.php';
require_once '../EbatNs/GetItemRequestType.php';
$session = new EbatNs_Session('config/ebay.config.php');
$cs = new EbatNs_ServiceProxy($session);
$cs->_logger = new EbatNs_Logger();
$req = new VerifyAddItemRequestType();
$item = new ItemType();
$item->BuyItNowPrice;
$item->Description = 'test ��� � <b>Some bold text</b>';
$item->ListingDuration = 'Days_7';
$item->Title = '��� test-titel';
$item->Currency = 'EUR';
$item->ListingType = 'Chinese';
$item->Quantity = 1;
$item->StartPrice = new AmountType();
$item->StartPrice->setTypeValue('1.0');
$item->StartPrice->setTypeAttribute('currencyID', 'EUR');
$item->Country = 'GB';
$item->Location = '-- not given --';
$item->ConditionID = '1';
$item->PrimaryCategory = new CategoryType();
$item->PrimaryCategory->CategoryID = 11450;
$returnPolicy = new ReturnPolicyType();
$returnPolicy->setRefundOption($sellerConfig['refund']['option']);
$returnPolicy->setRefund($sellerConfig['refund']['option']);
$returnPolicy->setReturnsWithinOption($sellerConfig['refund']['within']);
$returnPolicy->setReturnsWithin($sellerConfig['refund']['within']);
$returnPolicy->setReturnsAcceptedOption($sellerConfig['refund']['returns']);
$returnPolicy->setReturnsAccepted($sellerConfig['refund']['returns']);
$returnPolicy->setDescription($sellerConfig['refund']['description']);
$returnPolicy->setShippingCostPaidByOption($sellerConfig['refund']['paidby']);
$returnPolicy->setShippingCostPaidBy($sellerConfig['refund']['paidby']);
$item->ReturnPolicy = $returnPolicy;
$item->Site = 'UK';
$item->ShipToLocations[]="Europe";
$item->PaymentMethods[] = 'PayPal';
$item->PayPalEmailAddress = 'paypal#intradesys.com';
$req->Item = $item;
$res = $cs->VerifyAddItem($req);
?>
You're going to have to get a newer toolkit. ReturnPolicy was added 3 1/2 years ago in 581.
Also, the lowest supported schema is now 629. I would recommend using as new of a toolkit as you can find. It looks like eBay hasn't updated their PHP page in a while, so you should go directly to the toolkit developer website to see what they have there.
Hope this helps!
Just started digging into the YouTube PHP API and got the browser-based Zend upload script working. However, I can't find any documentation on how to retrieve the status of the video after it's been uploaded. The main reason I would need this is for error handling - I need to be able to know whether the video was approved by YouTube, since someone could technically upload an image or a file too large. I need to know that the vid was approved so that I know what message to display the end user when they return to the site (ie 'Your video is live' or 'Video upload failed').
The YouTube PHP browser-based upload returns a URL parameter status of 200 even if the format or size is incorrect, which is of course not helpful. Any ideas on how else to get this info from the YT object?
All in all, when a user returns to the site, I want to be able to create a YT object based on their specific video ID, and want to be able to confirm that it was not rejected. I'm using ClientLogin to initiate the YouTube obj:
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = 'myuser#gmail.com',
$password = 'mypassword',
$service = 'youtube',
$client = null,
$source = 'MySource', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
Any thoughts?
Whew, finally found the answer to this after searching around and piecing together code for the last few days. After you create the $yt object, use the following to check the status:
$yt->setMajorProtocolVersion(2);
$youtubeEntry = $yt->getVideoEntry('YOUR_YOUTUBE_VID_ID', null, true);
if ($youtubeEntry->getControl()){
$control = $youtubeEntry->getControl();
$state = $control->getState()->getName();
}
Echoing out $state displays the string 'failed' if the video was not approved for whatever reason. Otherwise it's empty, which means it was approved and is good to go (Guessing the other state names would be: processing, rejected, failed, restricted, as Mient-jan Stelling suggested above).
Crazy how tough this answer was to put together for first-time YouTube API'ers. Solved! (Pats self on back)
Do you have a CallToken if so its pretty easy.
For this example i use Zend_Gdata_Youtube with Zend AuthSub.
WHen uploading your video you had a CallToken, With this call token you can access the status of the video.
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = 'myuser#gmail.com',
$password = 'mypassword',
$service = 'youtube',
$client = null,
$source = 'MySource', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$youtube = new Zend_Gdata_YouTube( $httpClient, '', NULL, YOUTUBE_DEVELOPER_KEY );
$youtubeEntry = $youtube->getFullVideoEntry( 'ID_OF_YOUTUBE_MOVIE' );
// its the 11 digit id all youtube video's have
in $youtubeEntry all your data about the video is present
$state = $youtubeEntry->getVideoState();
if state is null then your video is available else make of state a string like this.
(string) $state->getName();
There are about 4 important state names. ( processing, rejected, failed, restricted)
Hi guys I'm trying to update my google contacts using the zend framework but I'm getting the following error:
Expected response code 200, got 403 If-Match or If-None-Match header or entry etag attribute required
The following is my code:
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_Feed');
$client = getGoogleClient('cp'); // this is a function I made - its working fine
$client->setHeaders('If-Match: *');
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
$query = new Zend_Gdata_Query($id);// id is the google reference
$entry = $gdata->getEntry($query);
$xml = simplexml_load_string($entry->getXML());
$xml->name->fullName = trim($contact->first_name).' '.trim($contact->last_name);
$entryResult = $gdata->updateEntry($xml->saveXML(), $id);
Whats going on?
i got a solution in http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14476692
here is the message from that link:
// in listing 6... // somewhere before
the updateEntry call add:
$extra_header = array();
$extra_header='*';
// and then replace the current
updateEntry call with the following:
$entryResult =
$gdata->updateEntry($xml->saveXML(),$entry->getEditLink()->href,null,$extra_header);
Updates to Google Contacts now work.
i get it work for my code. again there is a problem with the code in the post as well.
that is
$extra_header = array();
$extra_header = array('If-Match'=>'*');
$entryResult = $contactObj->updateEntry($xml->saveXML(),$entry->getEditLink()->href,null,$extra_header);
I think it will help you solve the update problem as well.
thanks