简体   繁体   English

VK通过php自动发布在墙上

[英]VK auto-post in wall via php

I would like to post on my wall in vk.com some photos, texts, etc via PHP. 我想通过PHP在vk.com上发布一些照片,文本等。 From a couple of days I'm trying to understand the official guides of VK ( https://vk.com/dev/PHP_SDK ) and some scipt found in GitHub ( https://github.com/fdcore/vk.api ). 几天后,我试图了解VK的官方指南( https://vk.com/dev/PHP_SDK )和GitHub中的一些scipt( https://github.com/fdcore/vk.api ) 。

There are few lines of code but I struggle to get to the second or third line. 几行代码,但我很难到达第二行或第三行。

I get immediately php errors, JSON errors, etc etc etc. I can't even make myself give the first Access_token, Autorization_code etc. I admit I don't understand much about OAuth and API, but here I can't even begin. 我立即得到php错误,JSON错误等等。我甚至不能让自己给第一个Access_token,Autorization_code等。我承认我对OAuth和API不太了解,但在这里我甚至无法开始。

Even the names of things are strange, secret_key, secure_key, api_key, I think they are always the same, but I'm not sure anymore, but they one gives me, I think it's her. 即使是事物的名字也很奇怪,secret_key,secure_key,api_key,我认为它们总是一样,但我不确定,但是他们给了我一个,我认为这是她的。

Do these APIs work? 这些API有用吗? Is there a guide for dummy? 假人有指南吗? That you guide me step-by-step, just to understand if I did something wrong, even if I made very few steps. 你一步一步指导我,只是为了理解我是否做错了,即使我做了很少的步骤。

Or maybe there is some other script or class that works? 或者也许还有其他一些脚本或类可以工作?

I'm guessing as a start, you will need code similar to below, not forgetting about downloading the VK class library from Github https://github.com/fdcore/vk.api/blob/v2/src/vk.php . 我猜你是一个开始,你需要类似下面的代码,不要忘记从Github https://github.com/fdcore/vk.api/blob/v2/src/vk.php下载VK类库。

<?php

    // Need to have the vk.php in the same directory.
    include 'vk.php';

    // Please complete the below with your details/credentials.
    $config['secret_key'] = '';
    $config['client_id'] = '';
    $config['user_id'] = '';
    $config['access_token'] = '';
    $config['scope'] = 'wall,photos,friends,groups';

    // Get a new instance of VK.
    $v = new Vk($config);

    // Define the attachment to insert, in this case an image.
    $attachments = $v->upload_photo(0, array('1737759.jpg'));

    // Post the message and image to your wall.
    $response = $v->wall->post(array(
       'message'=>'test 1737759.jpg',
       'attachments' => implode(',', $attachments)
    ));

?>

The class deals with all of the behind the scene coding and talking to Vk as a whole. 该课程处理所有幕后编码并与Vk整体交谈。 And why reinvent the wheel! 为什么重新发明轮子!

Everybody stop! 大家都停下来!

I deleted the application and I made a new one... and it works... I have a working URL and a working token. 我删除了应用程序并创建了一个新的...它可以运行...我有一个工作URL和一个工作令牌。

However it is strange, these days I have done many tests tried many scripts and created and deleted apps several times always with the same settings (Standalone)... Just now he liked it and it worked... 然而奇怪的是,这些天我做了很多测试尝试了很多脚本并且使用相同的设置创建和删除应用程序几次(独立)...刚才他喜欢它并且它有效......

Now with the code that gave me Jim Grant and the token, everything works, I can upload photos on the wall of VK via PHP. 现在有了代码给了我吉姆格兰特和令牌,一切正常,我可以通过PHP上传VK墙上的照片。

To have the URL with the token I used this: 要使用我使用此令牌的URL:

$v = new Vk(array(
    'client_id' => 123456, // (required) app id
    'secret_key' => '', // (required) get on https://vk.com/editapp?id=12345&section=options
    'user_id' => 12345, // your user id on vk.com
    'scope' => 'wall,photos,friends,groups', // scope access
    'v' => '5.52' // vk api version
));

$url = $v->get_code_token();

echo $url;

Then I granted the permissions and took the token from the URL in the address bar. 然后我授予了权限并从地址栏中的URL中获取了令牌。

And then I used the Jim Grant code with the new token, and everything works. 然后我使用了Jim Grant代码和新令牌,一切正常。 Really simple, when everything works. 当一切正常时,真的很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM