Node.js에서 실시간으로 JSON 데이터를 가져오는 방법이 있을까요?

익명 사용자의 이미지

플레이스테이션에서 플레이 중인 게임을 디스코드에 Rich Presence로 표시하고 싶어서 Node.js로 스크립트를 만들었습니다. 하지만 실행 시에만 플레이스테이션 네트워크에서 정보를 불러오기 때문에 스크립트 실행 도중에 플레이스테이션에서 유저의 상태가 변경(오프라인 또는 온라인, 플레이 중인 게임 변경)될 시 반영되지가 않습니다. 아래는 스크립트의 일부분입니다.

// PSN 토큰 확인
await psn.auth(npsso);

console.log('access_token: ' + psn.access_token + '\n' + 'refresh_token: ' + psn.refresh_token + '\n');

// 프로필 정보 JSON 형식으로 불러오기
const profile = await psn.getProfile("Florize_gt");

const username = profile.onlineId;
const titleName = profile.presence.primaryInfo.gameTitleInfo.titleName;
const titleId = profile.presence.primaryInfo.gameTitleInfo.npTitleId;
const platform = profile.presence.primaryInfo.platform;

console.log('Username: ' + username);
console.log('Platform: ' + platform);
console.log('Now Playing: ' + titleName);

// 디스코드 Rich Presence 업데이트      
client.updatePresence({
    state: platform + '에서 플레이 중',
    details: titleName,
    startTimestamp: Date.now(),
    largeImageKey: titleId.toLowerCase(),
    smallImageKey: 'smallimage',
    largeImageText: titleName,
    smallImageText: platform,
    instance: true
});

위와 같이 스크립트에 psn.getProfile이라는 함수가 쓰입니다. pxs-psn-api라는 라이브러리를 가져다 썼는데, 그 라이브러리 안에 request로 PSN에서 JSON을 불러와 파싱하는 과정까지 모두 들어가 있습니다. 그래서 스크립트에서는 파싱된 데이터를 가져다 쓰기만 하면 되는 것입니다. 하지만 그 라이브러리에서 request의 헤더로 Url과 Authentication에 필요한 Token을 필요로 합니다. 이를 어떻게 해야 실시간으로 JSON 데이터를 가져올 수 있을 지 궁금합니다. 해당 라이브러리 링크입니다. 링크

peecky의 이미지

getProfile()을 일정시간 간격으로 계속 호출하면 되는 거 아닌가요?

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.