one23/php-8-graph-sdk

PHP 8 的 Facebook SDK

1.0.1 2022-12-16 09:58 UTC

This package is auto-updated.

Last update: 2024-09-16 13:32:59 UTC


README

此仓库包含开源PHP SDK,允许您从PHP应用程序中访问Facebook平台。

安装

composer require one23/php-8-graph-sdk

分支

此仓库是从废弃的facebook/graph-sdk分支而来的。

有什么不同

  • 命名空间:\Facebook\ -> \One23\GraphSdk
  • Facebook::__construct需要'default_graph_version'
  • 移除废弃的类
    • GraphNodes\GraphList -> GraphEdge
    • GraphNodes\GraphObject -> GraphNode
    • GraphNodes\GraphObjectFactory -> GraphNodeFactory
  • 移除特性
    • PseudoRandomStringGeneratorTrait
  • 替换废弃的方法
    • FacebookResponse
      • getGraphObject() -> getGraphNode()
      • getGraphList() -> getGraphEdge()
    • Authentication\AccessTokenMetadata
      • getProperty() -> getField()
    • GraphNodes\Collection
      • getProperty() -> getField()
  • 重命名和重构类
    • FacebookApp -> App
    • FacebookBatchRequest -> BatchRequest
    • FacebookBatchResponse -> BatchResponse
    • FacebookClient -> Client
    • FacebookRequest -> Request
    • FacebookResponse -> Response
    • 异常\
      • FacebookAuthenticationException -> AuthenticationException
      • FacebookAuthorizationException -> AuthorizationException
      • FacebookClientException -> ClientException
      • FacebookOtherException -> OtherException
      • FacebookResponseException -> ResponseException
      • FacebookResumableUploadException -> ResumableUploadException
      • FacebookSDKException -> SDKException
      • FacebookServerException -> ServerException
      • FacebookThrottleException -> ThrottleException
    • FileUpload\
      • FacebookFile -> File
      • FacebookResumableUploader -> ResumableUploader
      • FacebookTransferChunk -> TransferChunk
      • FacebookVideo -> Video
    • Helpers\
      • FacebookSignedRequestFromInputHelper -> AbstractSignedRequestFromInput
    • HttpClients\
      • FacebookCurl -> Curl
      • FacebookStream - Stream
      • FacebookHttpClientInterface -> Clients\ClientInterface
      • FacebookCurlHttpClient -> Clients\Curl
      • FacebookGuzzleHttpClient -> Clients\Guzzle
      • FacebookStreamHttpClient -> Clients\Stream
    • PersistentData\
      • PersistentDataInterface -> Handlers\PersistentDataInterface
      • FacebookMemoryPersistentDataHandler -> Handlers\Memory
      • FacebookSessionPersistentDataHandler -> Handlers\Session
    • PseudoRandomString\
      • McryptPseudoRandomStringGenerator -> Generators\Mcrypt (废弃)
      • OpenSslPseudoRandomStringGenerator -> Generators\OpenSsl
      • RandomBytesPseudoRandomStringGenerator -> Generators\RandomBytes
      • UrandomPseudoRandomStringGenerator -> Generators\Urandom
      • PseudoRandomStringGeneratorInterface -> Generators\GeneratorInterface
      • PseudoRandomStringGeneratorFactory -> GeneratorFactory
    • Url\
      • FacebookUrlManipulator -> Url\Manipulator
      • UrlDetectionInterface -> Url\DetectionInterface
  • 废弃(将在下一个版本中删除)
    • FacebookApp
    • FacebookBatchRequest
    • FacebookBatchResponse
    • FacebookClient
    • FacebookRequest
    • FacebookResponse
    • 异常\
      • FacebookAuthenticationException
      • FacebookAuthorizationException
      • FacebookClientException
      • FacebookOtherException
      • FacebookResponseException
      • FacebookResumableUploadException
      • FacebookSDKException
      • FacebookServerException
      • FacebookThrottleException
    • FileUpload\
      • FacebookFile
      • FacebookResumableUploader
      • FacebookTransferChunk
      • FacebookVideo
    • Helpers\
      • FacebookSignedRequestFromInputHelper
    • HttpClients\
      • FacebookCurl
      • FacebookCurlHttpClient
      • FacebookGuzzleHttpClient
      • FacebookHttpClientInterface
      • FacebookStream
      • FacebookStreamHttpClient
    • PersistentData\
      • PersistentDataInterface
      • FacebookMemoryPersistentDataHandler
      • FacebookSessionPersistentDataHandler
    • PseudoRandomString\
      • McryptPseudoRandomStringGenerator
      • OpenSslPseudoRandomStringGenerator
      • PseudoRandomStringGeneratorFactory
      • PseudoRandomStringGeneratorInterface
      • RandomBytesPseudoRandomStringGenerator
      • UrandomPseudoRandomStringGenerator
      • Generators\Mcrypt

新增功能

  • 支持PHP 8.1
  • 修复guzzle请求
  • 全局异常:\One23\GraphSdk\Exception
  • FileUpload\Mimetypes - 替换为 \GuzzleHttp\Psr7\MimeType
  • PersistentData\Handlers\SessionLaravel
  • PersistentData\Handlers\SessionPhalcon

用法

use \One23\GraphSdk;

$fb = new GraphSdk\Facebook([
  'app_id' => '{app-id}',
  'app_secret' => '{app-secret}',
  'default_graph_version' => 'v15.0',
  //'default_access_token' => '{access-token}', // optional
]);

// Use one of the helper classes to get a GraphSdk\Authentication\AccessToken entity.
//   $helper = $fb->getRedirectLoginHelper();
//   $helper = $fb->getJavaScriptHelper();
//   $helper = $fb->getCanvasHelper();
//   $helper = $fb->getPageTabHelper();

try {
  // Get the GraphSdk\GraphNodes\GraphUser object for the current user.
  // If you provided a 'default_access_token', the '{access-token}' is optional.
  $response = $fb->get('/me', '{access-token}');
} 
catch(GraphSdk\Exceptions\ResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} 
catch(GraphSdk\Exceptions\SDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

$me = $response->getGraphUser();
echo 'Logged in as ' . $me->getName();

安全

如果您发现任何与安全相关的问题,请通过电子邮件 eugene@krivoruchko.info 联系,而不是使用问题跟踪器。

许可证

MIT