dirkgroenen / pinterest-api-php

A PHP wrapper for the official Pinterest API. :pushpin:
https://developers.pinterest.com/docs/getting-started/introduction/
Apache License 2.0
173 stars 76 forks source link

Warning About autoload.php #37

Closed helloarpitgshah closed 8 years ago

helloarpitgshah commented 8 years ago

Hey,

I have added your API with the Core PHP and make the Request to get the Login URL and then after access the token based on the code.

But I got the following errors,

Warning: require(../vendor/autoload.php): failed to open stream: No such file or directory in

Can you please help me asap?

dirkgroenen commented 8 years ago

As the warning says you're autoload.php can't be found. Are you sure you're pointing it to the right directory?

helloarpitgshah commented 8 years ago

Yes, I have just upload all your files at the Server and just call the index.php within the demo folder.

I got this error. I hadn't use the composer. I am using as simple Core PHP.

dirkgroenen commented 8 years ago

You'll have to run composer install so the package is actually installed.

helloarpitgshah commented 8 years ago

How can I do with this? I don't know about the composer. Does it work for the Simple PHP?

helloarpitgshah commented 8 years ago

is it possible do without using composer?

dirkgroenen commented 8 years ago

You can do it without composer, but that would mean you'll have to manually include every file in your project. You might want to read into composer to get an idea of what it does and why you'll probably want to use it.

helloarpitgshah commented 8 years ago

I have read the composer but still don't know much more about it.

Do you have any zip folder that manually include all the files and working good?

smvanbru commented 8 years ago

Dirk, Thanks so much for all the work you've put into this project. Have found it very helpful!

As much as Composer is a great way to load libraries (and the way I do it!) I wonder if providing an autoload file people can use independent of Composer would reduce the number of requests you keep getting from people seeking help in learning how to use composer. I know it shouldn't be your problem. But it's likely to keep coming up unless you have a simple autoload.php file of your own as part of the package. Many of the other libraries I use offer both composer and non-composer install instructions (presumably to address this).

helloarpitgshah commented 8 years ago

Yes, it would be great. Good News that- I have include all the files manually within the include.

There are one error now.

{ "message": "405: Method Not Allowed", "type": "http" }

Do you know why do we have this type of error now?

smvanbru commented 8 years ago

I believe an "autoload.php" file in the project root like this would do the job:

<?php
spl_autoload_register(function ($class) {

    // project-specific namespace prefix
    $prefix = 'DirkGroenen\\Pinterest\\';

    // base directory for the namespace prefix
    $base_dir = __DIR__ . '/src/Pinterest/';

    // does the class use the namespace prefix?
    $len = strlen($prefix);
    if (strncmp($prefix, $class, $len) !== 0) {
        // no, move to the next registered autoloader
        return;
    }

    // get the relative class name
    $relative_class = substr($class, $len);

    // replace the namespace prefix with the base directory, replace namespace
    // separators with directory separators in the relative class name, append
    // with .php
    $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';

    // if the file exists, require it
    if (file_exists($file)) {
        require $file;
    }
});
dirkgroenen commented 8 years ago

I personally feel no need to support people with an alternative way to load the classes, but as you said there are indeed (too) many issues about the subject (wonder when people stopped reading READMEs)...

Let me think about adding an autoload.php file as an alternative way to install. In the meantime; could you show me some repos which support an autoload file as alternative?

dirkgroenen commented 8 years ago

@helloarpitgshah about the error you're getting: please check if you're doing everything correctly and if you believe you do please open an other issue describing the steps and code you're executing.

smvanbru commented 8 years ago

I hear ya -- only reason I even suggest it is that as an active user of this library, I'm following the discussions, and am getting annoyed with all the requests for help with composer. It's become pretty standard, but lots of developers/hobbyists have never taken the time to figure it out.

Facebook and Google's official PHP SDK libraries provide both composer and autoload.php options. I guess they didn't want to have to deal with providing support for those who didn't know how to use composer either. And that's how I see it. You shouldn't have to provide customer support for that. Adding this basic file means you don't have to. https://github.com/facebook/facebook-php-sdk-v4/ https://github.com/google/google-api-php-client

helloarpitgshah commented 8 years ago

Yes, Exactly. Facebook have already include the auload.php so once We are going to include it will be automatically added all the classes.

Good News from here - I have run successfully post pin at pintrest API. I will message you if any help then :)

I am also planning to create autoload.php and post it here.

dirkgroenen commented 8 years ago

Your statement makes sense @smvanbru, for all the people who aren't using composer I've added the autoload.php file. It's available in 0.2.9.