#StackBounty: #php #api #reddit Post a link and add a comment on reddit with php

Bounty: 50

I would like to create a cronjob that regularly posts links to reddit (images on imgur) and adds a comment to the posted link.

I found something like this https://github.com/jcleblanc/reddit-php-sdk

and I created this script which publishes the links on reddit

<?
    require_once('reddit/reddit.php');
    $reddit = new reddit();
    
        $response = $reddit->createStory('title', 'https://i.imgur.com/....', 'funny');
    
    $pageInfo = $reddit->getPageInfo("https://i.imgur.com/...");
    
    
    
    echo var_dump($response);
    echo '<br><br>-------------------------------------------------------------------<br><br>';
    echo var_dump($pageInfo);
    
    echo '<br><br>-------------------------------------------------------------------<br><br>';
    
    echo 'name: '.$pageInfo->name;
    
    $response = $reddit->addComment('name from pageInfo', 'comment');
    ?>

Links work, but I can’t get name from $pageInfo, I’m missing something, but I am really lost and confused…

$pageInfo var_dump, cuted bacause too long…

object(stdClass)#2 (2) {
  ["kind"]=>
  string(7) "Listing"
  ["data"]=>
  object(stdClass)#3 (5) {
    ["modhash"]=>
    NULL
    ["dist"]=>
    int(1)
    ["children"]=>
    array(1) {
      [0]=>
      object(stdClass)#4 (2) {
        ["kind"]=>
        string(2) "t3"
        ["data"]=>
        object(stdClass)#5 (108) {
          ["approved_at_utc"]=>
          NULL
          ["subreddit"]=>
          string(15) "funny"
          ["selftext"]=>
          string(0) ""
          ["author_fullname"]=>
          string(8) "t2_mgufp"
          ["saved"]=>
          bool(false)
          ["mod_reason_title"]=>
          NULL
          ["gilded"]=>
          int(0)
          ["clicked"]=>
          bool(false)
          ["title"]=>
          string(11) "test title3"
          ["link_flair_richtext"]=>
          array(0) {
          }
          ["subreddit_name_prefixed"]=>
          string(17) "r/funny"
          ["hidden"]=>
          bool(false)
          ["pwls"]=>
          NULL
          ["link_flair_css_class"]=>
          NULL
          ["downs"]=>
          int(0)
          ["thumbnail_height"]=>
          int(140)
          ["top_awarded_type"]=>
          NULL
          ["hide_score"]=>
          bool(false)
          ["name"]=>
          string(9) "t3_hjgx8u"


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.