与 Poshmark 交互的不官方 PHP SDK

0.1.0 2020-06-05 15:41 UTC

This package is auto-updated.

Last update: 2024-09-06 03:38:52 UTC


README

Build Status Code Coverage Software License Latest Commit Coded in PhpStorm

PHP composer 包,用于与 Poshmark 网站和 API 交互。目前该工具使用您的浏览器 cookie 信息来执行此操作。

需求

  • php >= 7.1

支持的 API

使用方法

将 composer 包添加到您的项目中。

# TODO: This is not in packagist yet
composer require michaelbutler/phposh

使用方法和示例

设置用于所有方法调用的服务对象

<?php

require_once 'vendor/autoload.php';

/*
 * The way this works is, it needs the cookie data from your logged-in Poshmark browser session.
 * Simple way to get this is:
 * - Log in to www.poshmark.com
 * - Press Ctrl/Command + Shift + e (Firefox)
 *      - In Chrome, Ctrl/Command + Shift + i then click Network tab
 * - Refresh the page
 * - Right click the very top web request in the list and choose Copy as cURL
 * - Paste into a Text Document and then find the information after `Cookie:`
 * - If you ever get an error, repeat the steps above to get the latest cookie data.
 */

$cookieString = "ps=....; _csrf=....; ...";
$pmService = new \PHPosh\Provider\Poshmark\PoshmarkService($cookieString);

然后您可以使用该 $pmService 对象进行进一步调用,以获取或更改数据;请继续阅读。

getItems

检索您的衣柜中所有活跃(未售出)的项目

$allItems = $pmService->getItems();

foreach ($allItems as $item) {
    echo sprintf("itemId: %s - %s (%s)\n", $item->getId(), $item->getTitle(), $item->getPrice());
}

// Print the raw data array as provided by Poshmark
print_r($allItems[0]->getRawData());

列出另一个用户的项目

$userUuid = 'abc123def456....'; // userUuid can be found in the HTML code of a user's closet web page
$username = 'coolshop';
$allItems = $pmService->getItems($userUuid, $username);

foreach ($allItems as $item) {
    echo sprintf("itemId: %s - %s (%s)\n", $item->getId(), $item->getTitle(), $item->getPrice());
}

getItem

通过其标识符(id)检索单个项目。

// Use the itemId found via getItems or from an order
$item = $pmService->getItem('abc123def456....');

echo sprintf("itemId: %s - %s (%s)\n", $item->getId(), $item->getTitle(), $item->getPrice());

// The item's raw data element gives you all possible data provided by Poshmark,
// as a nested array map.
$rawData = $item->getRawData();

echo "Department: " . $rawData['department']['display'] . "\n";
echo "Num. Shares: " . $rawData['aggregates']['shares'] . "\n";

print_r($rawData);

getOrderSummaries

检索您的订单摘要列表

// Get 50 most recent orders.
// Not all details are available in the order summaries.
$orders = $pmService->getOrderSummaries(50);

foreach ($orders as $order) {
    echo sprintf("orderId: %s - %s (%s)\n", $order->getId(), $order->getTitle(), $order->getBuyerUsername());
    echo sprintf("Status: %s, Num. Items: %d\n", $order->getOrderStatus(), $order->getItemCount());
}

请注意,“订单摘要”不包含订单的完整详细信息。它包括

  • 订单标题
  • 销售价格
  • 尺寸(仅限单个项目订单)
  • 买家用户名
  • 订单状态
  • 缩略图(仅第一项)

getOrderDetail

要获取有关订单的所有详细信息

// Following example above
$orderId = $orders[0]->getId();
$details = $pmService->getOrderDetail($orderId);

echo "\n";
echo sprintf("Order Title: %s\n", $details->getTitle());
echo sprintf("Buyer: %s\n", $details->getBuyerUsername());
echo sprintf("Total: %s\n", $details->getOrderTotal());
echo sprintf("Earnings: %s\n", $details->getEarnings());

echo "Items:\n";

foreach ($details->getItems() as $index => $item) {
    echo sprintf("%d: %s [%s] (%s)\n", $index + 1, $item->getTitle(), $item->getSize(), $item->getPrice());
}

updateItem

编辑并发布更改(例如,列表价格或项目描述)到项目数据

$itemFields = [
    // Only the below 4 fields are currently supported. Send at least one, multiple supported.
    'title' => 'Calvin Klein Jeans',
    'price' => '29.00 USD', // also "$29.00" is supported
    'description' => 'Great condition very comfortable jeans. One small tear on the left front pocket',
    'brand' => 'Calvin Klein',
];

try {
    $result = $pmService->updateItem('abc123def456...', $itemFields);
} catch (\PHPosh\Exception\DataException $e) {
    echo "ERROR: Item abc123def456... failed to update!! " . $e->getMessage();
    exit(1); 
}

echo "SUCCESS: Item abc123def456... updated!!\n";

贡献

这是该库的非常早期的版本,欢迎帮助。

需要的事项

  • 更多的 Poshmark 功能
  • 更好的认证机制

许可证

MIT