如何使用Powershell,从Microsoft Graph API下载并保存收到的用户照片

    const CleanWebpackPlugin = require("clean-webpack-plugin");
    const HtmlWebpackPlugin = require("html-webpack-plugin");
    const MiniCssExtractPlugin = require("mini-css-extract-plugin");
    const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
    const webpack = require("webpack");
    const path = require("path");
    const glob = require("glob");

    function htmlPlugins() {
      return glob
        .sync('./html/**/index.html')
        .map(item => {
          var dir = path.dirname(item);
          var newPath = dir.substr(dir.indexOf('/html') + 8);
          return new HtmlWebpackPlugin({
            hash: true,filename: newPath === '' ? 'index.html' : `${newPath}/index.html`,template: path.resolve(__dirname,`${item}`)
          });
        });
    };

    // Plugins configuration
    let buildPath = path.resolve(__dirname,"dist");
    let cleanOptions = {
      root: __dirname,verbose: true
    };

    // Webpack configuration
    module.exports = {
      entry: glob.sync("./assets/dep.js"),mode: "development",output: {
        path: buildPath,filename: "app.js"
      },module: {
        rules: [
          {
            test: /\.html$/,use: { loader: "html-loader?interpolate" }
          },{
            test: /\.(scss|css)$/,use: [MiniCssExtractPlugin.loader,"css-loader","sass-loader"]
          },{
            test: /\.(gif|png|jpe?g|svg)$/i,use: {
              loader: 'file-loader',options: {
                name: '[name].[ext]',outputPath: 'img'
              }
            }
          },{
              test: require.resolve("jquery-migrate"),use: "imports-loader?define=>false",},{
            test: /\.(ttf|eot|woff|woff2)$/,use: {
              loader: "file-loader",outputPath: 'fonts'
              }
            }
          },{
            test: /(sitemap.xml|robots.txt|favicon.ico)/,use: ["file-loader?name=[name].[ext]"]
          }
        ]
      },plugins: [
        new CleanWebpackPlugin(buildPath,cleanOptions),new webpack.ProvidePlugin({ $: "jquery",jQuery: "jquery" }),new MiniCssExtractPlugin({
          filename: "[name].css",chunkFilename: "[id].css"
        }),new BrowserSyncPlugin({
          host: 'localhost',port: 3000,server: { baseDir: ['dist'] }
        })
      ].concat(htmlPlugins())
    };

这使我得到如下响应:

$apiUrl = "https://graph.microsoft.com/v1.0/me/photo/$value"
Invoke-RestMethod -Headers @{Authorization = "Bearer $($Tokenresponse.access_token)"} -Uri $apiUrl -Method Get

我没有下一步的方法。 我的目标是: 1.将照片保存到变量(我相信是字节数组)。要么 2.或者将照片直接下载到.jpeg文件中。

jayxh314 回答:如何使用Powershell,从Microsoft Graph API下载并保存收到的用户照片

最后从这里的另一个问题,我可以找出我的代码存在的问题。 The solution was to escape the $value at the end of the url with `$value

本文链接:https://www.f2er.com/3159699.html

大家都在问