youthweb/php-youthweb-api

Youthweb API client

Maintainers

πŸ‘ Art4

Package info

github.com/youthweb/php-youthweb-api

pkg:composer/youthweb/php-youthweb-api

Statistics

Installs: 58

Dependents: 0

Suggesters: 0

Stars: 3

Open Issues: 2

0.10.0 2021-03-05 12:17 UTC

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

GPL-3.0-or-later 128cb4d5cb6a8604fccc714da4305c12ed916b5f

apiyouthweb

This package is auto-updated.

Last update: 2026-06-15 23:24:44 UTC


README

πŸ‘ Latest Version
πŸ‘ Software License GPLv3
πŸ‘ Build Status
πŸ‘ codecov

PHP Youthweb API ist ein objektorientierter Wrapper in PHP 8.0+ fΓΌr die Youthweb API.

Installation

Composer:

$ composer require youthweb/php-youthweb-api

Dokumentation / Anwendung

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

// Config
$client_id = 'CB91ZullPa4ync4l';
$client_secret = 'YC7CXuDXX9pF5SeTKs9enkoPjbV01QIs';
$redirect_url = 'http://localhost/php-youthweb-api/login-button.php';
$scope = ['user:read']; // See http://developer.youthweb.net/api_general_scopes.html
//A resource owner identifier to separate the caches
$resourceOwnerId = 'a24d4387-f4de-4318-929a-57d475162fd4'; // or '12345' or 'user@example.com'

require 'vendor/autoload.php';

$config = Configuration::create(
 $client_id,
 $client_secret,
 $redirect_url,
 $scope,
 $resourceOwnerId,
);

// optional: set other options, providers, etc
$config->setApiVersion('0.20');
$config->setCacheItemPool(new \Symfony\Component\Cache\Adapter\FilesystemAdapter());
$config->setHttpClient(new \GuzzleHttp\Client());

$client = \Youthweb\Api\Client::fromConfig($config);

echo '<h1>Mit Youthweb einloggen</h1>';
echo '<form method="get" action="'.$redirect_url.'">
<input name="go" value="Login" type="submit" />
</form>';

if ( isset($_GET['go']) )
{
 try {
 // (1) Try access the API
 $me = $client->getResource('users')->showMe();
 } catch (\Youthweb\Api\Exception\UnauthorizedException $th) {
 // (2) We need to ask for permission first
 header('Location: '.$th->getAuthorizationUrl());
 exit;
 }

 // (4) We have access to the API \o/
 printf('<p>Hallo %s %s!</p>', $me->get('data.attributes.first_name'), $me->get('data.attributes.last_name'));
 printf('<p>Deine Email-Adresse: %s', $me->get('data.attributes.email'));
}
elseif ( isset($_GET['code']) )
{
 // (3) Here we are if we have a permission
 $client->authorize('authorization_code', [
 'code' => $_GET['code'],
 'state' => $_GET['state'],
 ]);

 header('Location: '.$redirect_url.'?go=Login');
 exit;
}

Weitere Informationen zur Anwendung gibt es in der Dokumentation.

Tests

phpunit

Changelog

Der Changelog ist hier zu finden und folgt den Empfehlungen von keepachangelog.com.

Todo

  • Erstellen von Posts auf Endpoint /{object}/{object_id}/posts
  • Zugriff auf /events Resourcen
  • Zugriff auf /friends Resourcen
  • Zugriff auf /{object}/{id}/friends Resourcen