Zend Framework GData Youtube Loading issue - youtube-api

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

Related

Calling Another Project's Controller From A Project In The Same Solution (.NET Core )

There are 2 projects in the same solution. First project is a .NET Core project and it has all the codes(controllers, models etc.) related to packages. I need to get the information (id, name, description) of the packages and display it in the second project(.NET Core Web App with Razor). Is it possible to do it without changing the first project? I only want to show the package list on a single web page.
I tried calling the first project's controller but it didn't work. Maybe I missed a point. Any help is appreciated.
This requirement can be achieved, please see the gif image below.
Tips
If you want to call another project's controller from a project in the same solution, you need to make sure there is in HomeController in both project. I mean the name of any class should be unique in both projects.
Otherwise you will face the same issue like my homepage.
Test Code:
public List<PackageReference> GetPackageList5(string projectname)
{
List<PackageReference> list = new List<PackageReference>();
PackageReference p = null;
XDocument doc = XDocument.Load(_webHostEnvironment.ContentRootPath+ "/"+ projectname + ".csproj");
var packageReferences = doc.XPathSelectElements("//PackageReference")
.Select(pr => new PackageReference
{
Include = pr.Attribute("Include").Value,
Version = pr.Attribute("Version").Value
});
Console.WriteLine($"Project file contains {packageReferences.Count()} package references:");
foreach (var packageReference in packageReferences)
{
p = new PackageReference();
p.Version= packageReference.Version;
p.Include= packageReference.Include;
list.Add(packageReference);
//Console.WriteLine($"{packageReference.Include}, version {packageReference.Version}");
}
return list;
}
My Test Steps:
create two project, Net5MVC,Net6MVC
add project reference.
My .net6 project references a .net5 project. So in my HomeController (.net), I add below:
using Net5MVC.ForCore6;
using Net5MVC.Models;
Suggestion
When we reference the .net5 project in .net6 project, we can build success, but when we deploy it, it always failed. The reason is some file was multiple publish output files with the same relative path.
Found multiple publish output files with the same relative path:
D:\..\Net6\Net6\Net5MVC\appsettings.Development.json,
D:\..\Net6\Net6\Net6MVC\appsettings.Development.json,
D:\..\Net6\Net6\Net5MVC\appsettings.json,
D:\..\Net6\Net6\Net6MVC\appsettings.json.
And usually will add class library to current project, not add a web project.
As we know we can find packages info in .csproj file, so we need copy and paste .csproj file to publish folder.
I still recommend using the GetPackageList5 method above as an interface for your project, using HttpClient for requests.

How do i user open office in zf2 project

i have included the openoffice downloaded file to vendor folder, but i'm unable to access it and it when i do
$odf = new \Openoffice_Odf($templatePath, array('CLEAN_REMAINING_VARS' => true));
it gives me the error
Class 'Openoffice_Odf' not found
I think, you need to include it inside your script using include_path
require VENDOR_PATH.'OpenOffice/Odf.php';
or using a spl_autoloader

sfPHPCaptchaPlugin : The following code is invalid

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

Failed to open - Zend Framework

Warning: require_once(Zend/Application.php) [function.require-once]:
failed to open stream: No such file or directory in
D:\xampp\htdocs\obsessa\public\index.php on line 17
Fatal error: require_once() [function.require]: Failed opening
required 'Zend/Application.php'
(include_path='D:\xampp\htdocs\obsessa\library;.;D:/xampp/php/PEAR;D:/xampp/php/ZendFramework')
in D:\xampp\htdocs\obsessa\public\index.php on line 17
Hi Anyone help me on this ?
D:/xampp/php/PEAR;D:/xampp/php/ZendFramework
Should probably be:
D:/xampp/php/PEAR;D:/xampp/php/ZendFramework/library
The immediate problem is that your php include_path configuration is wrong. The reason is the way PSR-0 autoloading works. Your include path has two paths. If you want to load Zend\Application, then you need an include path that has a subdirectory called 'Zend'. In your case, D:/xampp/php/ZendFramework does not have that, you need D:/xampp/php/ZendFramework/library (which has a subdirectory named Zend, which has a file named Application.php)
But really, if you're doing ZF2, grab the skeleton application and use composer, just like the docs say, especially if you're new. composer is fantastic, and it's the preferred way to go. With composer, each application you write has its own installation of zf2. There are very few situations where you want your apps to rely on some globally-installed framework, which is the setup you're trying to do.
Please follow this step :
Please donwload the zend libray from zend official site
http://framework.zend.com/
Then paste donwloaded library in zend libray folder
Index.php file settings
//Ensure library/ is on include_path
set_include_path(
implode(PATH_SEPARATOR,
array(realpath(APPLICATION_PATH . '/../library'),
get_include_path(),)));
/** Zend_Application */
require_once 'Zend/Application.php';
please set index.php file as:
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(FILE) . '/../application'));
defined('LIBRARY_PATH')
|| define('LIBRARY_PATH', realpath(dirname(FILE) . '/../library'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
define('PUBLIC_PATH','http://'.$_SERVER['HTTP_HOST'].'/demo/public');
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
set_include_path(implode(PATH_SEPARATOR, array(
realpath(DOCTRINE_PATH),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();

What is the format for uploading images using twitteroauth?

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

Resources