Source: https://github.com/abraham/twitteroauth/pull/137
In the above-mentioned link, a Github user, Robhaswell, made an adjustment to Abraham's TwitterOAuth code and added an upload function for uploading images. This is a great addition to the framework, however, there was no proper documentation or example attached to the new code, so I'm having a bit of trouble using the function:
$image = 'weather.jpg';
$response = $tweet->upload('statuses/update_with_media', array(
'status' => 'This is a test',
'media[]' => "#{$image};type=image/jpeg;filename={$image}")
);
Whereas weather.jpg is in the same folder as the file with the code above.
Side note: The code will be executed through cron and upload an image that is always already present on the server, to twitter. Just to clarify that users won't have to be able to upload their images first and then submit them to Twitter via this script.
Can anyone point me in the right direction?
Edit: I'm aware this functionality is not part of the original build and I have updated the twitteroauth and OAuth code in accordance to Robhaswell's adjustment.
Since this question is still relevant, but the answer is now outdated I'll go ahead and update this question with a more up-to-date answer.
statuses/update_with_media has been deprecated by twitter. https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update_with_media.html
Here is my working code that uploads and tweets a status with a picture.
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret);
$content = $twitter->get("account/verify_credentials");
$tweet = "My tweet";
$imageMedia = $twitter->upload('media/upload', array('media' => '/path/to/image/image_name.png'));
$parameters = array(
"status" => $tweet,
"media_ids" => $imageMedia->media_id_string);
$statuses = $twitter->post("statuses/update", $parameters);
I just thought I would post this here since I stumbled across this question while looking for an answer for it.
Since I've been struggling with this, I thought answering this question might help some other people. This uses abraham's twitteroauth with the added image upload functionality (code can be found here)
You should check if your image-path is correct. It has to point to a file on your server (relative).
Also, make sure the host is correct in the twitteroauth file (see upload function, where it briefly changes the host url, this isn't necessary anymore). You should now use
https://api.twitter.com/1.1/
instead of
https://upload.twitter.com/1/
Keeping these two things in mind following code should work (it does for me);
$this->api = new TwitterOAuth($consumerKey, $consumerSecret,$token, $token_secret);
$attachment = "./images/img.jpg";
$image = "#{$attachment};type=image/jpeg";
$status = "Text";
$result = $this->api->upload('statuses/update_with_media',array('status'=>$message,'media[]'=>$image));
Related
So I've search everywhere. Xamarin Docs, goggle, here, W3.
All I need to do is store some small data in an XML file.
I created the XML, got the code lined up and when i go to build it.
IOS.....Can't find file.
I've googled the answer countless times, and they all say the same thing, Make sure it is set as Content or make sure it is "Embedded Resource" I've tried it both ways, It can't find the file to access it. Is IOS really that stupid? No issues in Android, took it 30 secs. Add it to the Assets and boom there it is.
But How to get IOS to Recognize xml file(find it)?
the code is this
XDocuent doc = new XDocument.Load("StoredLogs.xml") <that line is where it throws the error, through all the break points that it is.
After this it steps through a loop to bind the data in the xml to an object
Logs a.Id = x.Element("Id).Value......
a.name......... and so
All i want is basic offline storage.
iOS really that stupid?
Yes :P
When you add the XML file as an EmbeddedResource, you need to read it from the assembly instead of the path
For example:
var readme = typeof(NameSpace.App).GetTypeInfo().Assembly
.GetManifestResourceStrean("resourcename.xml");
using (var sr = new StreamReader(readme)) {
//Read the stream
}
I have a Cordova/PhoneGap app which uses the camera to capture a picture. I need to access this picture to send to my server.
For Android I simply use $cordovaFile.readAsDataURL(cordova.file.dataDirectory, fileName)
However; on iOS the filename does not come back as such. My return value for iOS shows the path as
assets-library://asset/asset.JPG?id=539425FE-43AA-48E7-9865-D76348208AC7&ext=JPG
How can I access and read this image? I'd prefer to stick with $cordovaFile but just want to get it to work.
I am using CordovaCameraPreview plugin and the best I can get back from the picture taker handler seems to be something formed similar to:
assets-library://asset/asset.JPG?id=990355E1-200A-4E35-AAA1-7D461E3999C8&ext=JPG
assets-library://asset/asset.JPG?id=C49FF0EB-CCCB-45B2-8577-B13868D8DB29&ext=JPG
How can I convert this to a filename and path that I can read with $cordovaFile? According to their documentation (http://ngcordova.com/docs/plugins/file/) it looks like I need to use one of their paths for File System Layout. It works fine on Android using cordova.file.dataDirectory but can't figure out how to access on iOS
I've also tried using window.resolveLocalFileSystemURL(path) but am getting undefined as my result.
Update
I feel like I'm getting closer... using window.resolveLocalFileSystemURL(path,resolveOnSuccess, resOnError); I get more information
name: "assets-library"
fullPath: "/asset/asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG"
name: "asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG"
nativeURL: "assets-library://asset/asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG"
It looks like I now need to use the fullPath but still can't figure out how to access with $cordovaFile
If I try to use $cordovaFile.readAsDataURL(cordova.file.dataDirectory, data.name) where data.name is asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG I get a file not found error
Update 2
I have tried using every single File System Layout available at http://ngcordova.com/docs/plugins/file/ and receive the same File Not Found error on each one. Still no clue how to access a file in assets-library using $cordovaFile
I had success with a simple substitution, like this
fullPath = fullPath.replace("assets-library://", "cdvfile://localhost/assets-library/")
It works in iOS 9.3
I was struggling with a similar issue for a while, but I figured it out today. I also thought that the FileSystem APIs didn't work with assets-libary:// URIs -- but that is not the case.
You should be able to get access to the File object (as well as the actual image name) by using the following code:
resolveLocalFileSystemURL('assets-library://asset/asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG', function(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(event) {
console.log(event.target.result.byteLength);
};
console.log('Reading file: ' + file.name);
reader.readAsArrayBuffer(file);
});
});
I am trying to use Gdata package of Zend-2 framework to access Youtube API.
I have a successfully working version with Zend 1.9 version. I am trying to port them to Zend 2 framework version.
The folder structure is
C:\wamp\www\plugins\youtube\
C:\wamp\www\plugins\youtube\Zend\ (all default folders that comes with ZF2)
C:\wamp\www\plugins\youtube\Zend\ZendGData (downloaded separately from Zend Packages page)
I have added the path C:\wamp\www\plugins\youtube\ to the include_path by using set_include_path() function and have verified the same.
I am using the below code to create the YouTube object.
$yt = new ZendGData\YouTube();
I am getting the below error.
Class 'ZendGData\YouTube' not found
I am not how to use the auto-loading feature of ZF2. I tried to include the Loader/StandardAutoloader.php file. But still the same.
If I include the Zend\ZendGData\YouTube.php file I get the notice that the ZendGData\Media is not found.
Please let me know if I am missing something silly.
EDIT:
Some more information on what I have done now.
Based on search from Stackoverflow site, I did the below changes.
use Zend\Loader\StandardAutoloader;
use ZendGdata\YouTube;
require_once 'C:\wamp\www\plugins\youtube\Zend\Loader\StandardAutoloader.php';
$loader = new StandardAutoloader(array('autoregister_zf' => true));
$loader->register();
$yt = new Zend\ZendGData\YouTube();
Now I get the below error.
Class 'ZendGData\Media' not found
After a lot of trial and error with the AutoLoader, the below code worked for me. If someone is having the same issue, here is the solution.
require_once 'C:\wamp\www\youtube\Zend\Loader\StandardAutoloader.php';
$loader = new StandardAutoloader(array(
'autoregister_zf' => true,
'namespaces' => array(
'ZendGData' => 'C:\wamp\www\youtube\Zend\ZendGdata\')
)
);
$loader->register();
$yt = new ZendGData\YouTube();
I meet a very strange problem,I used sfPHPCaptchaPlugin to make captha to my form in sf1.4 project I worked on,all configuration and installation of plugin is correct but the captcha verification won't let me save data of form in database and tell me that the text is wrong but I'm sure I entered the same text showing in image of captcha and here is the line who get me the error :
'captcha' => new sfValidatorPHPCaptcha(array(), array('invalid' => 'The following code is invalid.')),
Someone had the same errore before please?
sfPHPCaptchaPlugin is not stable for symfony 1.4 as it said in the plugin information Here.
You can use sfCaptchaGDPlugin its a very good one, folow the intalation guide in README, and use this widget:
$this->widgetSchema['captcha'] = new sfWidgetCaptchaGD();
$this->validatorSchema['captcha'] = new sfCaptchaGDValidator(array('length' => 4));
If anyone has managed to get locally uploading images I'd be mightily appreciative of some help.
I've downloaded the latest version of nicEdit along with the nicUpload plug in (from nicedit.com - Version 0.9 r24 released June 7th, 2012).
I've also downloaded nicUpload.php from http://svn.nicedit.com//trunk/nicUpload/php/nicUpload.php
NicUpload.php - I've set NICUPLOAD_PATH and NICUPLOAD_URI both to 'images' which is the subfolder of where nicupload.php and nicEdit.js are located.
NicEdit.js - I've added the following to line 271:-
uploadURI : 'nicUpload.php?id=123',
I've given it an ID otherwise it was failing with an invalid ID code. But the ?id=123 isn't meant to be there. I've also set the iconsPath accordingly.
Line 1370 I've switched this:-
nicURI : 'http://api.imgur.com/2/upload.json',
for this:-
nicURI : 'http://www.mydomain.com/nicedit/nicUpload.php',
But I'm still getting "Failed to upload image". I've searched and searched and searched for answers to this and I'm getting close to having spent two days tinkering with it.
With a few debugging displays I can see that it's failing on line 46 of nicUpload.php where it says:-
$file = $_FILES['nicImage'];
$image = $file['tmp_name'];
$max_upload_size = ini_max_upload_size();
if(!$file) {...
That last IF is true and that's where it exits with the error.
Appreciate anyone being able to help.
The nicUpload.php script file laying around sucks and I don't even understand how it could work.
NicEditor uses imgur as the default image upload service. The source code follows the API format described here: http://api.imgur.com/resources_anon#upload
My suggestion would be to implement the API request and response defined there.
I did not use the niceedit upload function to do what you want. I managed to add a button to the link and img dropdown menu. The button opens a file manager window where you also can upload. I managed to put then de url of the image or document into the nicedit drop down img or url window. That is how I solved the problem.