0

Google 短縮 URL を使用してプロジェクトの多くの URL を短縮しようとしていますが、HTTPRequestException 未処理エラーが引き続き発生します。初めて実行したとき、そこにない.csファイルを見つけるように求められたので、それが原因だと推測しています。ビジュアルスタジオでこれを取得するためにナゲットインストーラーを使用しました。何か案は?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.Apis.Urlshortener.v1;
using Google.Apis.Oauth2;
using Google.Apis.Services;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;

namespace ShortenURL
{
class Program
{
    static void Main(string[] args)
    {
        var originalURL = "https://www.google.com/maps/place/Desert+Christian+Schools/@32.2367293,-110.8339121,16.75z/data=!4m7!1m4!3m3!1s0x86d66f1806d996d7:0xe8ac20e8cebb38b9!2s7525+E+Speedway+Blvd,+Tucson,+AZ+85710!3b1!3m1!1s0x86d66f1806d996d7:0x7b90764e4e6a25d8";
        string shortUrl = Shorten(originalURL);
        Console.WriteLine(shortUrl);
        Console.WriteLine("FINISHED");
        Console.ReadLine();
    }
    private const string key = "AIzaSyB3pfstkvAZzEVOy4dNHaKTuNmtDaG3XsI";
    public static string Shorten(string url)
    {
        UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer()
        {
            ApiKey = key,
            ApplicationName = "ShortenUrlAHLI"
        });
        var m = new Google.Apis.Urlshortener.v1.Data.Url();
        m.LongUrl = url;
        return service.Url.Insert(m).Execute().Id;
    }
}
}
4

1 に答える 1